IOS 自定义 UISegmentedControl
来源:互联网 发布:cf淘宝特卖 编辑:程序博客网 时间:2024/04/28 03:17
先看效果。。。。
毫不含糊,直接上代码
- -(void)createSegmentedControl{
- NSArray *arr=@[@"提醒", @"历史",@"好友"];
- UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:arr];
- if (iPhone4||iPhone5) {
- segmentedControl.frame = CGRectMake(0, 0, 180.0, 33.0);
- }else{
- segmentedControl.frame = CGRectMake(0, 0, 240.0, 33.0);
- }
- segmentedControl.center=CGPointMake(SIZEWIDTH/2, 22);
- ////背景 点击或未点击
- [segmentedControl setBackgroundImage:[UIImage imageNamed:@"messsegent6"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
- [segmentedControl setBackgroundImage:[UIImage imageNamed:@"messsegent5"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- ////中间的分割线
- [segmentedControl setDividerImage:[UIImage imageNamed:@"messline"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- [segmentedControl setDividerImage:[UIImage imageNamed:@"messline"] forLeftSegmentState:UIControlStateHighlighted rightSegmentState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
- NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor ,[UIColor clearColor],UITextAttributeTextShadowColor ,nil];
- [segmentedControl setTitleTextAttributes:dic1 forState:UIControlStateNormal];
- NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:HEXRGB(0xf7f539),UITextAttributeTextColor ,[UIColor clearColor],UITextAttributeTextShadowColor ,nil];
- [segmentedControl setTitleTextAttributes:dic2 forState:UIControlStateSelected];
- segmentedControl.backgroundColor=[UIColor clearColor];
- segmentedControl.layer.borderWidth=0.5;
- segmentedControl.layer.borderColor=[[UIColor whiteColor]CGColor];
- segmentedControl.layer.masksToBounds=YES;
- segmentedControl.layer.cornerRadius=16.5;
- segmentedControl.selectedSegmentIndex=0;
- [segmentedControl addTarget:self action:@selector(segChange:) forControlEvents:UIControlEventValueChanged];
- self.navigationItem.titleView=segmentedControl;
- }
- -(void)segChange:(UISegmentedControl *)sender{
- switch (sender.selectedSegmentIndex) {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- }
- }
0 0
- IOS-自定义UISegmentedControl
- IOS 自定义 UISegmentedControl
- IOS 自定义 UISegmentedControl
- 自定义UISegmentedControl
- 自定义UISegmentedControl
- 自定义UISegmentedControl
- 自定义UISegmentedControl
- IOS UISegmentedControl
- IOS UISegmentedControl
- ios开发中自定义 UISegmentedControl 中每个segment的tintcolor
- iOS开发控件之UISegmentedControl:基本属性与自定义
- ios UISegmentedControl 用法
- [IOS] iphone之UISegmentedControl
- IOS UISegmentedControl实例
- UISegmentedControl-IOS开发
- iOS-选择控件 UISegmentedControl
- IOS之UISegmentedControl
- 【iOS学习】----UISegmentedControl
- IOS控制UITextField输入字数
- web前端开发的点点滴滴---4.CSS选择器
- C++全局变量的声明和定义
- Android之ButterKnife--View注入框架
- Thread、Handler与HandlerThread、Handler使用
- IOS 自定义 UISegmentedControl
- Windows 下 Apache HTTP Server 安装、配置以及与 Tomcat 的整合(附图)
- 黑马程序员-------C中的运算符大集合
- 数据结构之链队列
- IOS汉字排序
- IOS横屏事件
- IOS delegate注册推送
- spring整合cxf方式发布的rest webservice,调用接口
- ssh连接不上解决