的字體顏色我嘗試從白色更改字體顏色爲黑色UISegmentedControl
(適用於iOS 4 *)如何改變UISegmentedControl
UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:itemTitle, nil]] autorelease];
button.momentary = YES;
button.segmentedControlStyle = UISegmentedControlStyleBar;
button.tintColor = [UIColor redColor];
for (id segment in [button subviews]) {
for (id label in [segment subviews]) {
if ([label isKindOfClass:[UILabel class]]) {
UILabel *titleLabel = (UILabel *) label;
[titleLabel setTextColor:[UIColor blackColor]];
}
}
}
UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
但文字顏色不改變。我應該怎樣改變UISegmentedControl
的文字顏色?
注意:此答案需要iOS 5. – Costique 2012-01-31 19:14:42
此答案不會更改字體顏色作爲主題發起者請求的字體大小。 pbibergal的答案更完整。 – 2012-12-19 16:09:15
這可行,但UITextAttributeFont的警告即將推出。而是使用「NSFontAttributeName」。所有感謝@johngraham從http://stackoverflow.com/questions/2280391/change-font-size-of-uisegmentedcontrol – mavericks 2015-09-22 10:29:21