0

当我将 adjustsFontSizeToFitWidth 设置为按钮 UILabel 时,文本会出现在按钮框架的一侧,我不知道为什么?

这是我的代码:

            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)

结果如下:

在此处输入图像描述

4

1 回答 1

0

对于单线集

shareBtn.titleLabel?.adjustsFontSizeToFitWidth = YES;

而不是这个

factLabel.adjustsFontSizeToFitWidth = true;

对于我们使用的多行

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);
于 2016-01-20T10:08:09.777 回答