是否可以为selected
的{{1}}和unselected
segment
的文字保留不同的字体颜色。任何帮助将不胜感激。
答案 0 :(得分:3)
// Instantiate as usual
NSArray *items = [NSArray arrayWithObjects:@"first", @"second", [UIImage imageNamed:@"image.png"], nil];
MCSegmentedControl *segmentedControl = [[MCSegmentedControl alloc] initWithItems:items];
// set frame, add to view, set target and action for value change as usual
segmentedControl.frame = CGRectMake(10.0f, 10.0f, 300.0f, 44.0f);
[self.view addSubview:segmentedControl];
[segmentedControl addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged];
// Set a tint color
segmentedControl.tintColor = [UIColor orangeColor];
// Customize font and items color
segmentedControl.selectedItemColor = [UIColor yellowColor];
segmentedControl.unselectedItemColor = [UIColor darkGrayColor];
如果使用Interface Builder,添加普通的UISegmentedControl,在Identity Inspector中将其类设置为MCSegmentedControl,在Attributes Inspector中设置Tint。
目前,不支持动画和以下UISegmentedControl方法:
- (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;
- (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment
以下是文件: