próbuję zmienić kolor czcionki z białego na czarny dla UISegmentedControl
(na iOS 4. *)Jak zmienić kolor czcionki z 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];
Ale kolor tekstu nie zmieniło. Co powinienem zrobić, aby zmienić kolor tekstu na UISegmentedControl
?
Uwaga: ta odpowiedź wymaga iOS 5. – Costique
Ta odpowiedź nie zmienia koloru czcionki, gdy żądany rozrusznik tematu, tylko rozmiar czcionki. Odpowiedź pbibergala jest bardziej kompletna. –
To działa, ale nadchodzi ostrzeżenie, ponieważ UITextAttributeFont jest przestarzałe. Zamiast tego użyj "NSFontAttributeName". Wszystko dzięki @johngraham z http://stackoverflow.com/questions/2280391/change-font-size-of-uisegmentedcontrol – mavericks