我尝试制作一个带有多行的标签,但它不起作用,每次我只得到1行和一部分字符串而不是两行
这是我在其中安装标签的视图
class ProfileTextView: UIView {
var titleLabel:UILabel = {
var label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont(name: "VAGWorld-Bold", size: 14)
label.numberOfLines = 0
label.lineBreakMode = .ByWordWrapping
return label
}()
var textView:UITextView = {
var textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.font = UIFont(name: "Helvetica", size: 12)
textView.textColor = UIColor.lightGrayColor()
textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0)
return textView
}()
var editButton:UIButton = {
var button = UIButton()
button.setTitle("Редактировать", forState: .Normal)
button.setTitleColor(UIColor(red: 5/255, green: 195/255, blue: 142/255, alpha: 1), forState: .Normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.titleLabel?.font = UIFont(name: "Helvetica-Bold", size: 10)
button.tag = 1
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(titleLabel)
titleLabel.topAnchor.constraintEqualToAnchor(topAnchor, constant: 0).active = true
titleLabel.leadingAnchor.constraintEqualToAnchor(leadingAnchor, constant: 0).active = true
titleLabel.trailingAnchor.constraintEqualToAnchor(trailingAnchor).active = true
titleLabel.heightAnchor.constraintEqualToConstant(18).active = true
addSubview(textView)
textView.topAnchor.constraintEqualToAnchor(titleLabel.bottomAnchor, constant: 4).active = true
textView.leadingAnchor.constraintEqualToAnchor(leadingAnchor, constant: -5).active = true
textView.trailingAnchor.constraintEqualToAnchor(trailingAnchor, constant: 0).active = true
addSubview(editButton)
editButton.topAnchor.constraintEqualToAnchor(textView.bottomAnchor,constant: 0).active = true
editButton.leadingAnchor.constraintEqualToAnchor(textView.leadingAnchor, constant: 5).active = true
editButton.heightAnchor.constraintEqualToConstant(16).active = true
editButton.bottomAnchor.constraintEqualToAnchor(bottomAnchor).active = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
这是我在其中插入带标签
的视图的viewcontrollerclass ProfileViewController:UIViewController {
lazy var sixThingsBlock: ProfileTextView = {
var block = ProfileTextView()
block.translatesAutoresizingMaskIntoConstraints = false
block.titleLabel.text = "Here goes large text that doesnt fits to one line and has to be transferred to second line"
block.textView.text = "Some text also"
block.textView.editable = false
block.editButton.addTarget(self, action: #selector(ProfileViewController.editHandler(_:)), forControlEvents: .TouchUpInside)
block.editButton.tag = 5
return block
}()
func viewDidload() {
scrollView.addSubview(sixThingsBlock)
sixThingsBlock.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor, constant: 20).active = true
sixThingsBlock.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor, constant: -20).active = true
sixThingsBlock.topAnchor.constraintEqualToAnchor(favoritesBlock.bottomAnchor, constant: 10).active = true
sixThingsBlockHeight = sixThingsBlock.heightAnchor.constraintEqualToConstant(70)
sixThingsBlockHeight!.active = true
}
我做错了什么?