How to make UILabel and UITextField font size to be relative to screen size

本秂侑毒 提交于 2020-01-07 05:42:12

问题


I have a view controller which has a text field and label and I have set height constraint for text field and label and so I feel font size is not relative to the screen I believe.

How can I make this items' font size to be relative to the screen size?


回答1:


You can manually change UIlabel or UITextfield font in viewDidLayoutSubviews method of your ViewController or layoutSubviews method of your superView. Like this:

CGRect screenSize = [UIScreen mainScreen].bounds;
textField.font = [UIFont fontWithName:@"YourFont-Name"  
    size:screenSize.size.width/15.f];


来源:https://stackoverflow.com/questions/46484498/how-to-make-uilabel-and-uitextfield-font-size-to-be-relative-to-screen-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!