一、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的更多相关文章

随机推荐

  1. 中国海洋大学第四届朗讯杯高级组 A Rocky

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2718&cid=1203 题意:给你一个m乘n的格子阵,从一边进去,直线往前走,如果前边有 ...

  2. 关于Failed to convert property value of type [org.quartz.impl.StdScheduler] to required type [org.springframework.scheduling.quartz.SchedulerFactoryBean

    在一个业务类有下列属性 private SchedulerFactoryBeanscheduler; public SchedulerFactory BeangetScheduler() { retu ...

  3. js构造函数

    使用函数做自动化 function createObj(nick, age){ var obj = { nick: nick, age: age, printName: function(){ con ...

  4. iCloud 包括文稿与数据、日历、提醒事项、 通讯录、备忘录、Safari书签

    iCloud 能够为用户在设备间同步数据和在服务器上保存数据.当前 iCloud 包括文稿与数据.日历.提醒事项. 通讯录.备忘录.Safari书签.阅读列表.iCloud Tabs.iBooks书签 ...

  5. wcf教程

    WCF Tutorial WCF stands for Windows Communication Foundation. It is a framework for building, config ...

  6. bzoj1705

    话说这题很久以前就写过,然后好像一直忘了写题解…… 以前看这道题还觉得挺难的,现在觉得好水 首先朴素的想法肯定是动归 f[i,j]表示到处理到第i根电线,最终高度为j的最小花费 f[i,j]:=min ...

  7. codeigniter实现ajax分页

    <?php /** *417 add 主要是实现ajax分页 **/ class MY_Pagination extends CI_Pagination{ public function __c ...

  8. 【 D3.js 进阶系列 — 6.2 】 饼状图的拖拽

    本文讲解稍微复杂一些的拖拽应用,即拖拽饼图的各部分. 在[入门 - 第 9.1 章]讲解了如何制作饼状图.饼状图的各部分是用具有宽度的弧线来表示的.在与用户进行交互的时候,如果每一部分都能拖拽,是很有 ...

  9. 分享你最喜欢的技巧和提示(Xcode,Objective-C,Swift,C...等等)

    http://www.cocoachina.com/ios/20151231/14846.html 笔者分享总结如下(本篇会不定期进行更新) : Objective-C 1.让Xcode的控制台支持L ...

  10. POJ2236 Wireless Network 并查集

    水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...