:uisegment 제어 I는 다음과 같이 할 UISegmentControl을 사용자 정의하는 노력했습니다
UISegmentControl에서 레이블을 통해우선 루프 내가하려고 할 때 여러 각을 설정하지만, 글꼴을 변경하지 않는 레이블 텍스트 속성을 변경하십시오. 나는 보통의 UILabel의에이 속성을 사용하여 시도하고 작동하지만,하지 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;
}
}];
}];
내에서 다음은 결과입니다 작품을 볼 부착
변경 label 속성 :
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;
레이블 변경 속성 링크 : Different font size in the same label?