更改UISegment控件的字体颜色和大小

时间:2011-09-27 09:44:18

标签: iphone uisegmentedcontrol

我想更改uisegment控件的字体颜色和字体大小。有可能吗?

如果有人这样做且任何人有解决方案,请告诉我或分享任何有用的链接

感谢。

3 个答案:

答案 0 :(得分:3)

更好地使用相同的图像

- (void)insertSegmentWithImage:(UIImage *)image  atIndex:(NSUInteger)segment animated:(BOOL)animated;

答案 1 :(得分:3)

正如其他一些答案所述,您也可以使用setTitleTextAttributes:forState:

UIFont *font = [UIFont boldSystemFontOfSize:12.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                       forKey:UITextAttributeFont];
[segmentedControl setTitleTextAttributes:attributes 
                                forState:UIControlStateNormal];

答案 2 :(得分:2)

检查此

NSArray *ary=[sgmntControl subviews];
NSInteger intCount=0;
for (id seg in ary) 
for (id label in [seg subviews]) 
if ([label isKindOfClass:[UILabel class]])
{
    if(intCount==1)
    {
        [label setTextColor:[UIColor blackColor]]; 
        [label setShadowColor:[UIColor whiteColor]];
    }
    else {
        [label setTextColor:[UIColor whiteColor]];
        [label setShadowColor:[UIColor blackColor]];
    }
    [label setFont:[UIFont boldSystemFontOfSize:16]];
    [label setShadowOffset:CGSizeMake(0,1)];

}

由于

相关问题