[英]How to adjustsFontSizeToFitWidth to UIButton label ? ios
when i set adjustsFontSizeToFitWidth to the button UILabel, the text go out side of the button frame, I don't know why ? 当我将AdjustsFontSizeToFitWidth设置为按钮UILabel时,文本超出了按钮框架的一侧,我不知道为什么?
here is my code: 这是我的代码:
shareBtn = UIButton()
shareBtn.setTitle(IconsConstants.share, forState: UIControlState.Normal)
shareBtn.titleLabel?.font = UIFont.iconmoonFont(100)
shareBtn.titleLabel?.adjustsFontSizeToFitWidth = true;
shareBtn.contentVerticalAlignment = UIControlContentVerticalAlignment.Center
shareBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center
//EdgeInsets
shareBtn.contentEdgeInsets = UIEdgeInsets.init(top: 10, left: 10, bottom: 10, right: 10)
and here is the result: 结果如下:
for single line set 用于单行设置
shareBtn.titleLabel?.adjustsFontSizeToFitWidth = YES;
instead of this 代替这个
factLabel.adjustsFontSizeToFitWidth = true;
for multiple line us use 对于多行我们使用
actLabel.numberOfLines = 0;
factLabel.lineBreakMode = NSLineBreakByWordWrapping;
CGSize maximumLabelSize = CGSizeMake(factLabel.frame.size.width, CGFLOAT_MAX);
CGSize expectSize = [factLabel sizeThatFits:maximumLabelSize];
factLabel.frame = CGRectMake(factLabel.frame.origin.x, factLabel.frame.origin.y, expectSize.width, expectSize.height);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.