gpt4 book ai didi

iphone - UISegmentedControl 选定和未选定段的不同字体颜色

转载 作者:行者123 更新时间:2023-12-03 19:43:43 35 4
gpt4 key购买 nike

Possible Duplicate:
How to change font color of UISegmentedControl

是否可以为 selected 的文本保留不同的字体颜色和unselected segmentUISegmentedControl 。任何帮助将不胜感激。

最佳答案

// 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

关于iphone - UISegmentedControl 选定和未选定段的不同字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195484/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com