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