3

可能重复:
如何更改 UISegmentedControl 的字体颜色

是否可以为selectedunselected segment的文本保留不同的字体颜色UISegmentedControl?任何帮助将不胜感激。

4

1 回答 1

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

以下是文件:

MCSegmentedControl.zip

于 2013-01-07T12:17:49.287 回答