UISegmentedControl

```

NSArray * arr = [NSArray arrayWithObjects:@"推送消息",@"系统消息", nil];

self.messageVC = [[UISegmentedControl alloc] initWithItems:arr];

_messageVC.selectedSegmentIndex = 0;//设置指定索引的题目

_messageVC.layer.cornerRadius = 16 * KY;//圆角

_messageVC.layer.borderColor = [UIColor colorWithHue:0.55 saturation:0.54 brightness:0.86 alpha:1.00].CGColor;//边框颜色

_messageVC.layer.borderWidth = 1;//边框宽度

_messageVC.layer.masksToBounds = YES;//是否剪切

_messageVC.tintColor = [UIColor colorWithHue:0.55 saturation:0.54 brightness:0.86 alpha:1.00];

//默认字体的大小和颜色

NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHue:0.00 saturation:0.00 brightness:0.43 alpha:1.00],NSForegroundColorAttributeName,[UIFont boldSystemFontOfSize:15],NSFontAttributeName, nil];

[_messageVC setTitleTextAttributes:dic forState:(UIControlStateNormal)];

// 添加监听

[_messageVC addTarget:self action:@selector(didClickSegmentedControlAction:)forControlEvents:UIControlEventValueChanged];

/**

*  监听点击了哪项

*/

- (void)didClickSegmentedControlAction:(UISegmentedControl *)segmentControl

{

NSInteger idx = segmentControl.selectedSegmentIndex;

NSLog(@"%ld", idx);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 9,167评论 2 7
  • 原文 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新。 1.UITableView的Group...
    无沣阅读 4,136评论 0 2
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,960评论 3 38
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 4,288评论 0 0
  • 获取磁盘总空间大小 //磁盘总空间 (CGFloat)diskOfAllSizeMBytes{CGFloat si...
    UILabelkell阅读 5,196评论 0 2