UI学习第三章 UISwitch   UISegment    UIAlertView    UIActionsheet

本文深入探讨了iOS开发中的关键UI组件,包括UISwitch、UISegment、UIAlertView和UIActionSheet的创建、配置与事件监听,提供实例代码指导。

UI学习第三章      UISwitch   UISegment    UIAlertView    UIActionsheet

一、UISwitch

1.创建
UISwitch *swi = [[UISwitch alloc]initWithFrame:CGRectMake(30,100, 200,40)];
2.设置开状态颜色
swi.onTintColor = [UIColorblueColor];
3.设置关状态周围颜色
swi.tintColor = [UIColor redColor];
4.设置圆框颜色
swi.thumbTintColor = [UIColor blackColor];
5.设置开关初始状态
swi.on = YES;(ison只能读取状态)
6.绑定事件
[swi addTarget:self action:@selector(my:) forControlEvents:UIControlEventValueChanged];
UISegment
1.创建(有标题,无边框)
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"1",@"2",@"3"]];
2.创建(有边框,无标题)
 UISegmentedControl *seg = [[UISegmentedControl alloc]initWithFrame:CGRectMake(20, 40, 200, 40)];
3.分段个数
 NSLog(@"%zi",seg.numberOfSegments);
4.在某个位置插入一个分段,注意:越界不报错
[seg insertSegmentWithTitle:@"分段4" atIndex:3 animated:YES];
5.给某一段设置标题
[seg setTitle:@"分段1" forSegmentAtIndex:0];
6.获取某一分段的标题
NSString *str = [seg titleForSegmentAtIndex:0];
7.获取某一分段的图片
UIImage *image = [seg imageForSegmentAtIndex:0];
8.设置某一分段的宽(不能设置高)
[seg setWidth:30 forSegmentAtIndex:1];
9.整体不被激活
[seg setEnabled:NO];
10.设置某一分段不被激活
[seg setEnabled:NO forSegmentAtIndex:0];
11.设置默认选中项
seg.selectedSegmentIndex = 2;
12.获取当前被选中的项
NSLog(@"%zi",seg.selectedSegmentIndex);
13.边框和选中颜色
seg.tintColor = [UIColor redColor];
14.设置背景图片
[seg setBackgroundImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
15.绑定监听事件
[seg addTarget:self action:@selector(my) forControlEvents:UIControlEventValueChanged];
16.移除某一分段   注意:越界不会报错
[seg removeSegmentAtIndex:0 animated:YES];
UIAlertView
1.创建
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提示内容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"按钮",@"按钮2",@"按钮3", nil];
2.设置标题
alert.title = @"新提示";
3.设置内容
alert.message = @"rwnrhnrtjnyhtyj";
4.弹出alert
[alert show];
5.方法:alert自动消失
[alert dismissWithClickedButtonIndex:2 animated:YES];
代理方法
1.输出按的是第几个按钮
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
   
NSLog(@"%zi",buttonIndex);
}
UIActionsheet(同UIAlertView)
控制UIActionsheet显示
[action showInView:self.view];
方法:
1.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{//显示选择
   
NSLog(@"%zi",buttonIndex);
   
NSLog(@"%@",[actionSheet buttonTitleAtIndex:buttonIndex]);
   
UITextField *text = (UITextField *)[self.view viewWithTag:8];
   
if (buttonIndex != 2) {
        text.
text = [actionSheet buttonTitleAtIndex:buttonIndex];
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值