Objective
For someone who's ever developed Android, without these basic attributes it's outrageous, or it's a table spray, write code--#
Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com
Body
classUilabelpadding:uilabel {Privatevar padding =Uiedgeinsetszero @IBInspectable var paddingleft:cgfloat {Get{returnPadding.left}Set{Padding.left =NewValue}} @IBInspectable var paddingright:cgfloat {Get{returnPadding.right}Set{padding.right =NewValue}} @IBInspectable var paddingtop:cgfloat {Get{returnPadding.top}Set{padding.top =NewValue}} @IBInspectable var paddingbottom:cgfloat {Get{returnPadding.bottom}Set{Padding.bottom =NewValue}} Overridefunc Drawtextinrect (rect:cgrect) {super.drawtextinrect (Uiedgeinsetsinsetrect (rect, padding))}OverrideFunc textrectforbounds (Bounds:cgrect, Limitedtonumberoflines numberoflines:int)CGRect {let insets=self.padding var rect=super.textrectforbounds (Uiedgeinsetsinsetrect (Bounds, insets), Limitedtonumberoflines:numberoflines) Rect.ori Gin.x-=Insets.left RECT.ORIGIN.Y-=insets.top rect.size.width+ = (Insets.left +insets.right) Rect.size.height+ = (Insets.top +insets.bottom)returnrect}}
Code Description:
Ibinspectable can be used to support uilable in the Storyboard can specify the internal margin, very convenient:
Reference
Refer to this article http://stackoverflow.com/questions/21167226/resizing-a-uilabel-to-accomodate-insets change, note this article http/ There's a problem with Stackoverflow.com/questions/3476646/uilabel-text-margin.
End
Sorry for naming with Android, and then Super Love ibinspectable this thing.
"Swift" UILabel set the inner margin