NSAttributext iOS

Thanh Nguyen
Answered Mar 5th, 2019 12:15 p.m.
Các font chữ tiếng Nhật thường bị như vậy. Cách khắc phục: Dùng custom class cho label, button... kiểu như này để tăng intrinsicContentSize height lên.
class CustomLabel: UILabel {
open override var intrinsicContentSize: CGSize {
var size = super.intrinsicContentSize
size.height += (0.275 * font.pointSize)
return size
}
override func sizeToFit() {
super.sizeToFit()
frame.size = intrinsicContentSize
}
}
class CustomButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
titleLabel?.sizeToFit()
if let titleLabel = self.titleLabel {
var frame = titleLabel.frame
let adjustHeight = 0.275 * titleLabel.font.pointSize
frame.size.height += adjustHeight
frame.origin.y -= (adjustHeight / 2)
titleLabel.frame = frame
}
}
}
+2
Organizations
Have no organizations yet.