let lbl = UILabel()
lbl.textColor = UIColor.RGB(0x74, g: 0x75, b: 0x75)
lbl.text = "180/180"
lbl.sizeToFit()
self.addSubview(lbl)
self.charsLimitLbl = lbl
lbl.translatesAutoresizingMaskIntoConstraints = false
let rightConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:[item]-padding-|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: ["padding" : padding],
views: ["item" : lbl])
self.addConstraints(rightVonstraints)
let bottomConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:[item]-padding-|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: ["padding" : padding],
views: ["item" : lbl])
self.addConstraints(bottomConstraints)
lbl.setContentHuggingPriority(UILayoutPriorityRequired, for: .horizontal)
我将此标签添加为UITextView的子视图,由于某种原因,我的标签产生了负面原因:
App.WPPUILabel:0x7f9132209830; baseClass = UILabel; frame =( -39.5 -14.5; 39.5 14.5); text =' 54/180&#39 ;; userInteractionEnabled = NO; layer = _UILabelLayer:0x63800009ddd0
我可以随时随地调用这些功能:
self.layoutIfNeeded()
self.layoutSubviews()
self.setNeedsLayout()