Class Viewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Super.viewdidload ()
Label
Let Label:uilabel = UILabel (Frame:cgrect (x:100, y:250, width:200, height:100))
Label.text = "Hello world!"
Self.view.addSubview (label)
label.textalignment =. Center
Set text highlighting
Label.ishighlighted = True
Set Text Highlight Color
Label.highlightedtextcolor = Uicolor.black
Rich Text Settings
Let AttributeString = nsmutableattributedstring (string: "Welcome")
Text font that changes the string at the specified position
Attributestring.addattribute (Nsfontattributename,
Value:UIFont.systemFont (OFSIZE:20),
Range:nsmakerange (0, 4))
Sets the font color for the specified position
Attributestring.addattribute (Nsforegroundcolorattributename, Value:UIColor.blue,
Range:nsmakerange (0, 3))
Sets the text background color for the specified position
Attributestring.addattribute (Nsbackgroundcolorattributename, Value:UIColor.green,
Range:nsmakerange (3,3))
Label.attributedtext = AttributeString
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any resources the can be recreated.
}
}
Swift Practice--UILabel