UISlider UISegment UISwitch UIStepper UIAlert
UISlider
1.初始化
UISlider *slider = [UISlider alloc] initWithFrame:CGRectMake(,,,)];
2.点击事件
slider addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
//当尺子记录的值发生的改变,会触发方法
3.在滑动过程中是否触发事件
slider.continuous = NO;
4.设置滑尺最大和最小的记录(默认是0~1)
slider.minimumValue = 10;
slider.maximumValue = 100;
5.修改滑尺上线条的颜色
slider.minimumTrackTintColor = [UIColor redColor];
slider.maximumTrackTintColor = [];
6.设置圆圈的图片
slider setThumbImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
UISegment
1.初始化
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"",@"",[UIImage imageNamed:@""],nil]];
//使用一个数组初始化一个选择器,数组里可以放字符串和图片(图片只取形状,不取颜色),实际应用中,一般都是要么都用字符串,要么都用图片
2.设置颜色
segment.tintColor = [UIColor redColor];
3.删除一个选择
[segment removeSegmentAtIndex:2 animated:YES];
4.插入一个选择
[segment insertSegmentWithTitle:@"" atIndex:1 animated:YES];
5.设置被选中的分段
segment.selectedSegmentIndex = 1;
6.点击事件
segment addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
7.- (void)segmentClick:(UISegmentedControl *)sender{ NSInteger index = sender.selectedSegmentIndex;}
UISwitch
1.初始化
UISwitch *sw = [[UISwitch alloc] initWithframe:CGRectMake(,,,)];//大小是51*31,固定的
2.设置打开状态,关闭状态和圆圈的颜色
sw.onTintColor = [UIColor redColor];
sw.tintColor = [UIColor blackColor];
sw.thumbTintColor = [UIColor greenColor];
3.开关状态
sw.on = YES;
4.开关的事件
sw addTarget:self action:@selector(swClick:) forControlEvents:UIControlEventValueChanged];
UIActivityIndicatiorView活动指示器
1.初始化
UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
2.显示在屏幕的正中间
aiv.center = self.view.center;
3.改变颜色
aiv.color = [];
4.开始活动
[aiv startAnimating];
UIWebView
1.初始化
UIWevView *wv = [[UIWebView alloc] initWithFrame:self.view.bounds];
2.将一个字符串转化成网址类的对象
NSString *urlStr = @"";
NSURL *url = [NSURL URLWithString:urlStr];
3.使用一个网络链接创建一个网络请求
NSURLRequest *request = [NSURLRequest requestWithURL:url];
4.网页视图开始加载网络请求
[wv loadRequest:request];
UIStepper
1.初始化
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(,,,)];//大小是固定的
2.设置颜色
stepper.tintColor = [UIColor redColor];
3.设置步长,一次加减的值
stepper.stepValue = 40;
4.最小和最大值
stepper.minimumValue = 10;
stepper.maximumValue = 300;
5.设置加号和减号的图片(只取形状,不取颜色)
[stepper setIncrementImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[stepper setDecrementImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
UIProgress
1.UIProgressView *pv = [[UIProgressView alloc] initWithFrame:CGRectMake(,,,)];
2.设置进度
pv.progress = 0.5;
3.进度条左边和右边的颜色
pv.progressTintColor = [UIColor redColor];
pv.trackTintColor = [UIColor greenColor];
UIAlert
1.初始化
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"通知" message:@"电量不足,是否充电" delegate:self cancelButtonTitle:@"no" otherButtonTitles:@"yes",@"oye", nil];
[av show];//让警告框显示在controller中
2.//警告框的点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld==%ld", alertView.tag, buttonIndex);
//在实际工作中,如果有多个警告框需要点击事件,那么得用alertView.tag来判断点击的是哪一个警告框,然后用buttonIndex判断点击的是 哪一个按钮
}
UIActionSheet
1.UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"分享到" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"朋友圈" otherButtonTitles:@"微信好友",@"qq空间",@"qq好友",@"微博", nil];
[as showInView:self.view];
2.//actionSheet的点击事件
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld======%ld",actionSheet.tag,buttonIndex);
//如果有多个as,得用tag值区分点击的是哪一个as,然后用下标判断点击的是哪一个按钮
}