Swift Practice--UILabel

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.