class UILabelOverride: UILabel { override func textRectForBounds(bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect { var rect = super.textRectForBounds(bounds, limitedToNumberOfLines: numberOfLines) rect.origin.x = CGFloat(10) return rect } override func drawTextInRect(rect: CGRect) { let aRect = self.textRectForBounds(rect, limitedToNumberOfLines: self.numberOfLines) super.drawTextInRect(aRect) } }
重写这两个方法之后就可以实现
时间: 2024-10-24 04:05:50