【发布时间】:2021-03-24 13:11:50
【问题描述】:
我试图让 NSMutableAttributedString 在文本达到宽度时返回多行。
我以为我可以使用 numberOfLines 但这只能通过 UILabel 访问?
理想情况下,“社区指南”和“条款与条件”文本都应位于“通过选中此框”下方。我该怎么做?
我用来创建attributedSting 的代码是
func setupView() {
let color = UIColor.white
let font = UIFont.systemFont(ofSize: 20)
let label = UIButton(type: .system)
label.backgroundColor = GREEN_Theme
let attributedTitle = NSMutableAttributedString(string:
"By checking this box, you agree to our", attributes: [NSAttributedString.Key.foregroundColor:
color, NSAttributedString.Key.font : font])
attributedTitle.append(NSAttributedString(string: "Community Guidelines", attributes: [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: font]))
label.addTarget(self, action: #selector(communityGuideLinesAction), for: .touchUpInside)
label.setAttributedTitle(attributedTitle, for: .normal)
view.addSubview(label)
let gesture = UITapGestureRecognizer(target: self, action: #selector(didTapCheckBox))
checkbox.addGestureRecognizer(gesture)
label.anchors(top: registerButton.bottomAnchor, topPad: 0, bottom: nil, bottomPad: 0, left: checkbox.rightAnchor, leftPad: 10, right: nil, rightPad: 0, height: 60, width: 300)
}
我正在尝试使用上面的文字,类似于下面的文字,但我不知道如何实现。
在更改了我选择约束属性字符串的方式之后,
这是我看到的。
【问题讨论】:
标签: ios swift nsmutableattributedstring nsmutablestring