问题
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