简体   繁体   中英

How to Adjust label size to change according to screen size

So I have 3 textFields, which I want to change the height according to which phone. For example, the label height increases if it's an iPhone 8+ vs an iPhone 8. This is my current code:

 let screensize = UIScreen.main.bounds.height
    expenseLabel.frame.size.height = screensize*0.1
    amountLabel.frame.size.height = screensize*0.1
    dateLabel.frame.size.height = screensize*0.1

However, this seems to have no effect on my code and it still displays the same height.

You can use size classes to support different size for different screens. Here is a good tutorial about using size classes :

https://www.raywenderlich.com/162311/adaptive-layout-tutorial-ios-11-getting-started

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