小编Flo*_*ori的帖子

UIStackView和截断的Multiline UILabels

我想添加几个多行标签UIStackView.

但我总是把我的标签截断.如此截图所示 截断原样

但我喜欢这里显示的更多(我伪造的截图) 截断它应该是

这是我的代码.首先,我创建父/主StackView,将其放入ScrollView(隐藏在屏幕中)

    stackView = UIStackView()
    stackView.axis = .Vertical
    stackView.distribution = .Fill
    stackView.spacing = 2
    stackView.translatesAutoresizingMaskIntoConstraints = false
    scrollView.addSubview(stackView)
    NSLayoutConstraint.activateConstraints(stackConstraints)


    let s1 = createHeaderStackView()
    stackView.insertArrangedSubview(s1, atIndex: 0)

    let lbl2 = makeLabel()
    lbl2.text = "Second One"
    stackView.insertArrangedSubview(lbl2, atIndex: 1)

    scrollView.setNeedsLayout()
Run Code Online (Sandbox Code Playgroud)

makeLabelmakeButton都只是辅助功能

func makeButton() -> UIButton {
    let btn = UIButton(type: .Custom)
    btn.backgroundColor = UIColor.lightGrayColor()
    return btn
}

func makeLabel() -> UILabel {
    let lbl = UILabel()
    lbl.font = UIFont.systemFontOfSize(18)
    lbl.setContentCompressionResistancePriority(1000, forAxis: .Vertical)
    lbl.setContentHuggingPriority(10, forAxis: …
Run Code Online (Sandbox Code Playgroud)

uilabel ios swift uistackview

12
推荐指数
1
解决办法
5596
查看次数

标签 统计

ios ×1

swift ×1

uilabel ×1

uistackview ×1