美文网首页
UIBaselineAdjustment 的作用

UIBaselineAdjustment 的作用

作者: 换个名字而已 | 来源:发表于2018-11-30 10:21 被阅读0次

    UILabel 的 baselineAdjustment 属性 控制当lable 中的文字自动缩小时如何调整文本的基线。

    baselineAdjustment 属性只有在UIlable 的  adjustsFontSizeToFitWidth = true 和 numberOfLines = 1 的时候才生效。

    baselineAdjustment 调整文字基线距lable 垂直中线的位置。

    具体效果

          

            let label =UILabel.init(frame:CGRect.init(x:0, y:100, width:100, height:30))

            label.backgroundColor = UIColor.green;

            label.text = "UIBaselineAdjustment.none"

            label.adjustsFontSizeToFitWidth = true

            label.baselineAdjustment = UIBaselineAdjustment.none

            label.numberOfLines=1

            let label1 =UILabel.init(frame:CGRect.init(x:110, y:100, width:100, height:30))

            label1.backgroundColor = UIColor.green;

            label1.text = "UIBaselineAdjustment.alignCenters"

            label1.adjustsFontSizeToFitWidth = true

            label1.baselineAdjustment = UIBaselineAdjustment.alignCenters

            label1.numberOfLines=1

            let label2 =UILabel.init(frame:CGRect.init(x:220, y:100, width:100, height:30))

            label2.backgroundColor = UIColor.green;

            label2.text = "UIBaselineAdjustment.alignBaselines"

            label2.adjustsFontSizeToFitWidth = true

            label2.baselineAdjustment = UIBaselineAdjustment.alignBaselines

            label2.numberOfLines=1

            self.view.addSubview(label)

            self.view.addSubview(label1)

            self.view.addSubview(label2)

            let vieline =UIView.init(frame:CGRect.init(x:0, y:115, width:400, height:0.3))

            vieline.backgroundColor = UIColor.red

            self.view.addSubview(vieline)

    相关文章

      网友评论

          本文标题:UIBaselineAdjustment 的作用

          本文链接:https://www.haomeiwen.com/subject/gsuccqtx.html