Swift UILabel Text size adjusts with width

Source: Internet
Author: User

The width of Swift Uilabel is generally fixed, but the text is sometimes long and sometimes short, how to do the text after the label width of the appropriate narrowing so that the reality completely

In fact, a lot simpler we call

Adjustsfontsizetofitwidth

can be achieved

                Let Label1=uilabel (Frame:cgrectmake (+, +))        label1.text= "Test Swift UILabel here to test the text size and label width adaptive and set minimum scaling"        Self.view. Addsubview (Label1)        label1.backgroundcolor=uicolor.graycolor () let                        Label2=uilabel (frame: CGRectMake (+, (+), (+))        label2.text= "Test Swift UILabel here to test the text size and label width adaptive"        Label2.adjustsfontsizetofitwidth=true        self.view addsubview (label2)        label2.backgroundcolor= Uicolor.graycolor () Let                        Label3=uilabel (Frame:cgrectmake (),        label3.text= "test Swift UILabel Here to test the text size and label width adaptive "        label3.adjustsfontsizetofitwidth=true        //0.6 Here is reduced to 0.6 times times not shrunk, if still more than then omit the reality superfluous part        label3.minimumscalefactor=0.6        self.view addsubview (label3)        label3.backgroundcolor= Uicolor.graycolor ()

Perform the above code test results

Welcome to the discussion if you have questions



Apple Development Group: 414319235 Welcome to join the Welcome discussion question

Apple Development Group: 414319235 Welcome to join the Welcome discussion question

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift UILabel Text size adjusts with width

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.