UI第六天
2016-03-12 15:39
316 查看
控件大集合
UISegmentcontroller 增加删除事件
UISlider 在一条上拖动
UISwitch 开关
UIActivityIndicatorView 菊花
UIProgressView 进度条
UIStepper 步进器(+/- num)
UIAlertView 提示(中间弹出的)
UIActionSheet 提示(下面的)
一些实用方法:
设置背景随机颜色:
vc.view.backgroundColor = [UIColor
colorWithRed:arc4random()%256/255.0
green:arc4random()%256/255.0
blue:arc4random()%256/255.0
alpha:1.0];
一些概念:
1.UISegmentedControl:
UISegmentedControl *segment = [[UISegmentedControl
alloc]
initWithItems:array];
/是否能连续选中 YES为能连续选中 NO不能
segment.momentary =
YES;
//添加点击事件
[segment
addTarget:self
action:@selector(pressSegment:)
forControlEvents:UIControlEventValueChanged];
- (void)pressSegment:(UISegmentedControl *)segment
{
switch (segment.selectedSegmentIndex) {
case 0:
{
}
break;
default:
break;
}
}
2.UISlider:
UISlider * slider = [[UISlider
alloc] initWithFrame:CGRectMake(40,
100, self.view.frame.size.width -
80, 20)];//高度设置没用
//按钮开始时所处位置
slider.value =
2.0;
//一条的最短
slider.minimumValue =
0.0;
//一条的长度
slider.maximumValue =
100.0;
//按钮左边的颜色
slider.minimumTrackTintColor = [UIColor
redColor];
//按钮右边的颜色
slider.maximumTrackTintColor = [UIColor
yellowColor];
//按钮上的图标
[slider setThumbImage:[UIImage
imageNamed:@"player2"]
forState:UIControlStateNormal];
- (void)sliderValueChange
{
UISlider *slider1 = (id)[self.view
viewWithTag:100];
float value = slider1.value;
value +=
1;
[slider1
setValue:value animated:YES];
NSLog(@"%f",slider1.value);
if (slider1.value == slider1.maximumValue)
{
[timer
invalidate];//跑完后停止,使定时器无效
// slider1.value = 0.0;//循环跑
}
}
3.UISwitch
UISwitch *sw = [[UISwitch
alloc] initWithFrame:CGRectMake(100,
100,
100, 100)];
sw.on =
YES;
sw.onTintColor = [UIColor
blackColor];
sw.thumbTintColor = [UIColor
whiteColor];
- (void)switchChange:(UISwitch *)sw
{
if (sw.isOn)
{
NSLog(@"********开关即将开启");
}
else
{
NSLog(@"XXXXXXXX开关即将关闭");
}
// sw.on = !sw.on;
}
4.UIActivityIndicatorView
/*
UIActivityIndicatorViewStyleWhiteLarge,
UIActivityIndicatorViewStyleWhite,
UIActivityIndicatorViewStyleGray,
*/
//设置菊花样式
indicatorView.activityIndicatorViewStyle =
UIActivityIndicatorViewStyleGray;
//设置当动画停止的时候,是否隐藏菊花 YES为隐藏
默认 NO为不隐藏
indicatorView.hidden =
NO;
[indicatorView
startAnimating];
//开启状态栏上的菊花
[[UIApplication
sharedApplication] setNetworkActivityIndicatorVisible:YES];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIActivityIndicatorView *indicatorView = (id)[self.view
viewWithTag:100];
[indicatorView
stopAnimating];
//关闭状态栏上的菊花
[[UIApplication
sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
5.UIProgressView
//设置进度值
范围是0.0-1.0
progressView.progress =
0.1;
[NSTimer
scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(valueChange)
userInfo:nil
repeats:YES];
- (void)valueChange
{
UIProgressView *progressView = (id)[self.view
viewWithTag:100];
float value = progressView.progress;
value +=
0.01;
[progressView
setProgress:value
animated:YES];
}
6.UIStepper:
stepper.value =
100.0;
stepper.minimumValue =
0.0;
stepper.maximumValue =
120.0;
stepper.stepValue =
4.0;
- (void)valueChange:(UIStepper *)stepper
{
UILabel *label = (id)[self.view
viewWithTag:100];
label.text = [NSString
stringWithFormat:@"%f",stepper.value];
}
7.UIAlertView:
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:@"提示"
message:@"上miss"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",@"下miss",@"XX",
nil];
alert.alertViewStyle =
UIAlertViewStyleLoginAndPasswordInput;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//获取输入框的内容
UITextField *userT = [alertView
textFieldAtIndex:0];
UITextField *passT = [alertView
textFieldAtIndex:1];
switch (buttonIndex) {
case 0:
{
}
break;
default:
break;
}
NSLog(@"%ld",buttonIndex);
}
8.UIActionSheet:
UIActionSheet *actionSheet = [[UIActionSheet
alloc] initWithTitle:@"拍照"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"警告"
otherButtonTitles:@"确定",
@"xxx",nil];
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld",buttonIndex);
}
UISegmentcontroller 增加删除事件
UISlider 在一条上拖动
UISwitch 开关
UIActivityIndicatorView 菊花
UIProgressView 进度条
UIStepper 步进器(+/- num)
UIAlertView 提示(中间弹出的)
UIActionSheet 提示(下面的)
一些实用方法:
设置背景随机颜色:
vc.view.backgroundColor = [UIColor
colorWithRed:arc4random()%256/255.0
green:arc4random()%256/255.0
blue:arc4random()%256/255.0
alpha:1.0];
一些概念:
1.UISegmentedControl:
UISegmentedControl *segment = [[UISegmentedControl
alloc]
initWithItems:array];
/是否能连续选中 YES为能连续选中 NO不能
segment.momentary =
YES;
//添加点击事件
[segment
addTarget:self
action:@selector(pressSegment:)
forControlEvents:UIControlEventValueChanged];
- (void)pressSegment:(UISegmentedControl *)segment
{
switch (segment.selectedSegmentIndex) {
case 0:
{
}
break;
default:
break;
}
}
2.UISlider:
UISlider * slider = [[UISlider
alloc] initWithFrame:CGRectMake(40,
100, self.view.frame.size.width -
80, 20)];//高度设置没用
//按钮开始时所处位置
slider.value =
2.0;
//一条的最短
slider.minimumValue =
0.0;
//一条的长度
slider.maximumValue =
100.0;
//按钮左边的颜色
slider.minimumTrackTintColor = [UIColor
redColor];
//按钮右边的颜色
slider.maximumTrackTintColor = [UIColor
yellowColor];
//按钮上的图标
[slider setThumbImage:[UIImage
imageNamed:@"player2"]
forState:UIControlStateNormal];
- (void)sliderValueChange
{
UISlider *slider1 = (id)[self.view
viewWithTag:100];
float value = slider1.value;
value +=
1;
[slider1
setValue:value animated:YES];
NSLog(@"%f",slider1.value);
if (slider1.value == slider1.maximumValue)
{
[timer
invalidate];//跑完后停止,使定时器无效
// slider1.value = 0.0;//循环跑
}
}
3.UISwitch
UISwitch *sw = [[UISwitch
alloc] initWithFrame:CGRectMake(100,
100,
100, 100)];
sw.on =
YES;
sw.onTintColor = [UIColor
blackColor];
sw.thumbTintColor = [UIColor
whiteColor];
- (void)switchChange:(UISwitch *)sw
{
if (sw.isOn)
{
NSLog(@"********开关即将开启");
}
else
{
NSLog(@"XXXXXXXX开关即将关闭");
}
// sw.on = !sw.on;
}
4.UIActivityIndicatorView
/*
UIActivityIndicatorViewStyleWhiteLarge,
UIActivityIndicatorViewStyleWhite,
UIActivityIndicatorViewStyleGray,
*/
//设置菊花样式
indicatorView.activityIndicatorViewStyle =
UIActivityIndicatorViewStyleGray;
//设置当动画停止的时候,是否隐藏菊花 YES为隐藏
默认 NO为不隐藏
indicatorView.hidden =
NO;
[indicatorView
startAnimating];
//开启状态栏上的菊花
[[UIApplication
sharedApplication] setNetworkActivityIndicatorVisible:YES];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIActivityIndicatorView *indicatorView = (id)[self.view
viewWithTag:100];
[indicatorView
stopAnimating];
//关闭状态栏上的菊花
[[UIApplication
sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
5.UIProgressView
//设置进度值
范围是0.0-1.0
progressView.progress =
0.1;
[NSTimer
scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(valueChange)
userInfo:nil
repeats:YES];
- (void)valueChange
{
UIProgressView *progressView = (id)[self.view
viewWithTag:100];
float value = progressView.progress;
value +=
0.01;
[progressView
setProgress:value
animated:YES];
}
6.UIStepper:
stepper.value =
100.0;
stepper.minimumValue =
0.0;
stepper.maximumValue =
120.0;
stepper.stepValue =
4.0;
- (void)valueChange:(UIStepper *)stepper
{
UILabel *label = (id)[self.view
viewWithTag:100];
label.text = [NSString
stringWithFormat:@"%f",stepper.value];
}
7.UIAlertView:
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:@"提示"
message:@"上miss"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",@"下miss",@"XX",
nil];
alert.alertViewStyle =
UIAlertViewStyleLoginAndPasswordInput;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//获取输入框的内容
UITextField *userT = [alertView
textFieldAtIndex:0];
UITextField *passT = [alertView
textFieldAtIndex:1];
switch (buttonIndex) {
case 0:
{
}
break;
default:
break;
}
NSLog(@"%ld",buttonIndex);
}
8.UIActionSheet:
UIActionSheet *actionSheet = [[UIActionSheet
alloc] initWithTitle:@"拍照"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"警告"
otherButtonTitles:@"确定",
@"xxx",nil];
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld",buttonIndex);
}
相关文章推荐
- UI第五天
- UI第四天
- UI第三天
- UI第二天
- UI第一天
- Bluetooth 4.0之Android 解说
- Building RESTful APIs with Tornado
- HDU 3836 - Equivalent Sets【强连通分量 基础题】
- UItabBarController
- QBImagePicker用法详解
- quick 3.3 display.newColorLayer setContentSize
- Debian安装Arduino IDE
- CodeForces - 622A Infinite Sequence (思想)水
- Codeforces--622A--Infinite Sequence(数学)
- Codeforces--622A--Infinite Sequence(数学)
- 《NumPy Beginner's Guide》笔记Chapter2
- UI控件--UIImageView
- UVa 540 - Team Queue
- 《iOS Human Interface Guidelines》——Image View
- 对于League of Legends的分析