如何使UILabel和UITextField字体大小相对于屏幕大小 [英] How to make UILabel and UITextField font size to be relative to screen size

查看:52
本文介绍了如何使UILabel和UITextField字体大小相对于屏幕大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有文本字段和标签的视图控制器,并且为文本字段和标签设置了高度限制,因此我觉得字体大小与我认为的屏幕无关.

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?

推荐答案

您可以在ViewControllerviewDidLayoutSubviews方法或superViewlayoutSubviews方法中手动更改UIlabelUITextfield字体.像这样:

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];

这篇关于如何使UILabel和UITextField字体大小相对于屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆