label文字从左上角开始

时间:2023-03-08 16:23:12
label文字从左上角开始
import UIKit

class TextUpperLeftLabel: UILabel {

    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)
} }

  

label文字从左上角开始