UISegmentedControl 的使用

/** 设置选择器 */
- (void)setUpSegmentCtr {
UISegmentedControl *segmentCtr = [[UISegmentedControl alloc] initWithItems:@[@"采购订单",@"销售订单"]];
self.navigationItem.titleView = segmentCtr;
[segmentCtr addTarget:self action:@selector(didClicksegmentedControlAction:) forControlEvents:UIControlEventValueChanged];
self.segmentCtr = segmentCtr;
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:EMCNavColor,
NSForegroundColorAttributeName,
[UIFont boldSystemFontOfSize:],
NSFontAttributeName,nil]; [ self.segmentCtr setTitleTextAttributes:dic forState:UIControlStateSelected]; NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName: [UIColor whiteColor]};
[self.segmentCtr setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal]; [self.segmentCtr setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefaultPrompt];
[self.segmentCtr setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefaultPrompt]; self.segmentCtr.tintColor = [UIColor whiteColor];
self.segmentCtr.apportionsSegmentWidthsByContent = NO;
self.segmentCtr.backgroundColor = [UIColor clearColor];
self.segmentCtr.selectedSegmentIndex = ;
}

再viewdidload中添加

- (void)viewDidLoad {
[super viewDidLoad]; /** 设置选择器 */
[self setUpSegmentCtr]; }

效果图如下:

UISegmentedControl 的使用

上一篇:NFS CIFS SAMBA 的联系和区别


下一篇:LeetCode 34 Search for a Range (有序数组中查找给定数字的起止下标)