如何更改UISegmentedControl的单个索引的字体大小? [英] How to change the font size of a single index for UISegmentedControl?

查看:173
本文介绍了如何更改UISegmentedControl的单个索引的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更改 UISegmentedControl 的字体大小的方法如下:

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

如何在中更改单个索引的字体大小UISegmentedControl ?或者更好的是,如果文本不适合(而不是上面,它有Abo ...),字体大小应该更小,


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


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.

解决方案

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];
    }
}

这篇关于如何更改UISegmentedControl的单个索引的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆