[英]How do I change the font of a UILabel in swift without changing the font size?
[英]How do I change the font of a UISegmentedControl in swift without changing the font size?
我想在不改变字体大小的情况下更改UISegmentedControl
的字体。
这是我的代码,但显然,在这种情况下我也改变了字体大小:
let attr = NSDictionary(object: UIFont(name: "Avenir", size: 12.0)!, forKey: NSFontAttributeName)
segmentedControl.setTitleTextAttributes(attr as [NSObject : AnyObject] , forState: .Normal)
我怎么解决这个问题?
尝试下面的代码,这不是正确的方法,但我们没有其他选择,那么我们应该通过这个wat
int fontSize;
for (id segment in [segmentedControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
fontSize = label.font.pointSize;
// Here you got the label, now use the font size from here
break;
}
}
}
现在你有了fontSize,现在你可以使用它来改变字体
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.