Ich habe versucht, UISegmentControl anpassen wie folgt aussehen:uisegment Steuerung mit diff Textgröße
Zuerst habe ich eine Schleife durch die Etiketten in UISegmentControl und stellen jeweils mehrzeilige, aber wenn ich versuche, Ändern Sie die Beschriftungstextattribute ändert es nicht die Schriftart. Ich habe versucht, dieses Attribut auf einem normalen UILabel verwenden und es funktioniert, aber nicht innerhalb uisegment
[segmentedControl.subviews enumerateObjectsUsingBlock:^(UIView * obj, NSUInteger idx, BOOL *stop) {
[obj.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[UILabel class]]) {
//Multiline
UILabel *_tempLabel = (UILabel *)obj;
[_tempLabel setNumberOfLines:0];
NSMutableAttributedString *attString =
[[NSMutableAttributedString alloc]
initWithString: @"monkey goat"];
[attString addAttribute: NSForegroundColorAttributeName
value: [UIColor redColor]
range: NSMakeRange(0,6)];
[attString addAttribute: NSFontAttributeName
value: [UIFont fontWithName:@"Helvetica" size:15]
range: NSMakeRange(0,6)];
[attString addAttribute: NSFontAttributeName
value: [UIFont fontWithName:@"Didot" size:24]
range: NSMakeRange(7,4)];
_tempLabel.attributedText = attString;
}
}];
}];
Dies ist das Ergebnis:
ändern Label Attribut angebracht Werke lesen:
NSMutableAttributedString *attString =
[[NSMutableAttributedString alloc]
initWithString: @"monkey goat"];
[attString addAttribute: NSForegroundColorAttributeName
value: [UIColor redColor]
range: NSMakeRange(0,6)];
[attString addAttribute: NSFontAttributeName
value: [UIFont fontWithName:@"Helvetica" size:15]
range: NSMakeRange(0,6)];
[attString addAttribute: NSFontAttributeName
value: [UIFont fontWithName:@"Didot" size:24]
range: NSMakeRange(7,4)];
self.label.attributedText = attString;
SO Links zu Attribut ändern: Different font size in the same label?