cvp
Nov 02, 2017 - 09:07
How to code this in Python using Objective-C?
class CustomLabel: UILabel {
var padding:UIEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
required init(frame: CGRect, padding: UIEdgeInsets) {
super.init(frame: frame)
self.padding = padding
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func drawText(in rect: CGRect) {
let changedRect: CGRect = CGRect(x: (rect.origin.x + padding.left), y: (rect.origin.y + padding.top), width: (rect.size.width - (padding.left + padding.right)), height: (rect.size.height - (padding.top + padding.bottom)))
super.drawText(in: changedRect)
}
}
Implement it in the following way.
let label:CustomLabel = CustomLabel(frame: CGRect(x: 0, y: 20, width: self.view.frame.size.width, height: 60), padding: UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20))