简体   繁体   中英

iOS & Xcode 6: Auto Layout Text Scaling on a Button

I have a Today Extension with a button and UIImage. The button and image scale and center themselves correctly except the button's text is not scaled. I am writing this extension in Swift. I have tried these so far:

myButton.titleLabel.adjustsFontSizeToFitWidth = true
myButton.adjustsFontSizeToFitWidth = true

Both return errors.

Without seeing more code or the specific errors, the only thing I can see is that titleLabel is an optional. As written, the compiler would show the error 'UILabel? does not have a member named 'adjustsFontSizeToFitWidth' 'UILabel? does not have a member named 'adjustsFontSizeToFitWidth' . Writing the line as myButton.titleLabel?.adjustsFontSizeToFitWidth = true should fix the error.

Also, UIButton doesn't have a member named 'adjustFontSizeToFitWidth' so the second line would throw the same error as above.

Try fixing that error as indicated above and see if your AutoLayout issue works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM