码迷,mamicode.com
首页 > 其他好文 > 详细

UISegmetControl

时间:2015-09-11 22:00:18      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

一、UISegmentControl是一个分段控件,父类是UIControl,内涵数个button,并且都有对应下标index;

 

    NSArray *titles = @[@"护卫队",@"三军仪仗队",@"步兵方队",@"炮兵方队"];

    

    UISegmentedControl  *SegmentedC = [[UISegmentedControl alloc]initWithItems:titles];

    SegmentedC.frame = CGRectMake(20, 40, 335, 40);

    SegmentedC.backgroundColor = [UIColor whiteColor];

    

    //    设置文字颜色

    SegmentedC.tintColor = [UIColor redColor];

    //    [SegmentedC setTintColor:[UIColor whiteColor]];

    

    //    默认选中项

    SegmentedC.selectedSegmentIndex =0;

    

    

    //    修改某项的title

    [SegmentedC setTitle:@"女兵方阵" forSegmentAtIndex:2];

    

    //    指定某项宽度

    [SegmentedC setWidth:100 forSegmentAtIndex:1];

    

    //    设置title  文字大小   颜色

    

    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor blueColor]};

    NSDictionary *dic1 = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor yellowColor]};

    

    [SegmentedC setTitleTextAttributes:dic forState:UIControlStateNormal];

    [SegmentedC setTitleTextAttributes:dic1 forState:UIControlStateSelected];

    

    //    添加点击事件

    [SegmentedC addTarget:self action:@selector(handleSegmented:) forControlEvents:UIControlEventValueChanged];

    

    

    

    [self.view addSubview:SegmentedC];

    

    

    [SegmentedC release];

 

UISegmetControl

标签:

原文地址:http://www.cnblogs.com/tig666666/p/4802063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!