iOS基石 —— 不常用的基础控件

UISwitch
    //创建一个开关控件,苹果给它固定的size(79*27),frame更改size无效
    //继承于UIControl 为事件驱动型控件
    UISwitch *st = [[UISwitch alloc] initWithFrame:CGRectMake(10,10,100,50)];
    //on 属性,控制开关的开闭(YES 开)
    st.on =YES;
    //事件驱动型,通过event事件,通知target对象执行action中的方法 (函数)
    //UIControlEventValueChanged 当控件的值发生变化时所对应的事件
    [st addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:st];
    self.view.backgroundColor = [UIColor blackColor];

UIActivityIndicatorView
    //加载等待提示控件,初始化的时候,设定风格样式
    UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];//控件的size固定
    //设置中心点为view的中心点
    activityView.center = self.view.center;
    activityView.tag = 100;
    [self.view addSubview:activityView];
    //让提示控件转动
    [activityView startAnimating];
    //[activityView stopAnimating];

UISlider
//创建一个滑块控件,高度固定23 frame设置高度无效果
    //继承自UIControl,为事件驱动型控件
    UISlider *sl = [[UISlider alloc] initWithFrame:CGRectMake(10,10,300,300)];
    //设置滑块的最大值,默认值(0.0  1.0)
    sl.maximumValue = 300;
    //设置滑块的最小值
    sl.minimumValue = 10;
    //设置滑块最初显示的数值,滑动滑块,伴随的value值的改变
    sl.value = 50;
    //控制滑块的值是否时时变化,默认为YES
    sl.continuous = NO;
    [sl addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:sl];

UISegmentControl  
    //分段选取器
    //初始化传递进去的NSArray里面放置字符串或图片
    NSArray *titles = [NSArray arrayWithObjects:@"火影",@"海贼王",nil];
    //分段选取器会根据文字内容给一个合适的size
    //事件驱动型控件
    UISegmentedControl *sg = [[UISegmentedControl alloc] initWithItems:titles];
    //设置frame
    //设置风格样式
    sg.segmentedControlStyle = UISegmentedControlStyleBar;
    sg.frame = CGRectMake(10,60,300,50);
    //设置哪个分段处于选中状态,不设置此属性,任何分段都处于非选中状态
    sg.selectedSegmentIndex = 0;
    //向分段选取器指定的位置插入标题
    [sg insertSegmentWithTitle:@"银魂" atIndex:1 animated:YES];
    [sg addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:sg];

UIStepper
 //步进器 固定的size (94*27), 事件驱动型控件
    UIStepper *st = [[UIStepper alloc] initWithFrame:CGRectMake(10,10,300,30)];
    //设置最大值
    st.maximumValue = 300;
    //设置最小值
    st.minimumValue = 10;
    //设置步长 (默认值为1 必须>0)(+一次增加的值/-一次减少的值)
    st.stepValue = 10;
    [st addTarget:self action:@selector(stepperValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:st];

UIProgressView
    //进度条,普通视图控件,高度固定9
    UIProgressView *progress = [[UIProgressView alloc] initWithFrame:CGRectMake(10,100,300,30)];
    //进度条的进度属性(默认为0,0.0-1.0),值大于1,进度条一直处于满格状态
    progress.progress = 0.1;
    progress.tag = 101;
    [self.view addSubview:progress];

UIAlertView
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"请充值" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];

 UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"facebook" otherButtonTitles:@"新浪微博",@"微信",nil];
            [sheet showInView:sheet];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"buttonIndex:%d",buttonIndex);
}

UIActionSheet   
- (void)shared:(UIButton *)btn{
    UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"微信" otherButtonTitles:@"腾讯微博",@"QQ",@"新浪微博", nil];

    [sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    UIButton * bu = (id)[self.view viewWithTag:100];
    if (buttonIndex == 1) {
        bu.backgroundColor = [UIColor redColor];
    }
    NSLog(@"%d",buttonIndex);
    [bu setTitle:actionSheet.title forState:UIControlStateNormal];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值