MessageViewController

```

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);

}

你可能感兴趣的:(MessageViewController)