实现步骤:
step1:首先写一个继承自UILabel的类PatientInfoCustomLabel;
step2:让所要实现该功能的label继承PatientInfoCustomLabel类即可。
import UIKit
class PatientInfoCustomLabel: UILabel {
override func awakeFromNib() {
super.awakeFromNib()
}
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
var textRect = super.textRect(forBounds: bounds, limitedToNumberOfLines: numberOfLines)
textRect.origin.y = bounds.origin.y
return textRect
}
override func drawText(in rect: CGRect) {
let actualRect = self.textRect(forBounds: rect, limitedToNumberOfLines: self.numberOfLines)
super.drawText(in: actualRect)
}
}
网友评论