How to change the font size of a single index for UISegmentedControl?

拜拜、爱过 提交于 2019-12-11 03:12:36

问题


The way to change the font size for a UISegmentedControl would be the following:

UIFont *font = [UIFont systemFontOfSize:13.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont];
[self.segment setTitleTextAttributes:attributes forState:UIControlStateNormal];

How can I change the font size for a single index in a UISegmentedControl? Or even better, if the text doesn't fit in the segment (instead of "Above", it has "Abo...") the font size should be smaller so that it can fit.


回答1:


Please try with below code

for (UIView *v in [[[segment subviews] objectAtIndex:0] subviews]) {
    if ([v isKindOfClass:[UILabel class]]) {
        UILabel *label=(UILabel *) v ;
        lable.font=[UIFont systemFontOfSize:13.0f];
    }
}


来源:https://stackoverflow.com/questions/30364868/how-to-change-the-font-size-of-a-single-index-for-uisegmentedcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!