class UILabel_2:UILabel{ open var insetEdge:UIEdgeInsets!; override func drawText(in rect: CGRect) { super.drawText(in: UIEdgeInsetsInsetRect(rect, insetEdge)) } }
使用
let testText = UILabel_2(frame: CGRect(x: 10, y: 8, width: 20, height: 34)); testText.insetEdge = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 20)