如何以编程方式更改文本字段的字体大小? [英] How to change textfield font size programmatically?

查看:51
本文介绍了如何以编程方式更改文本字段的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于创建文本字段的按钮,也有一个用于更改文本字段的字体的按钮.我创建了3个具有不同标题的按钮: 17,20,36 .我希望该按钮的功能更改文本字段的字体大小,该怎么办?

I have a button that creates a text field, I also have a button to change the text field's font. I created 3 button with different titles: 17,20,36. I want the functions of that button to change the font size of the text field, how can I do this?

推荐答案

如果只想更改文本字段的字体大小,而不是同时更改其字体样式,则下面的代码可能会起作用:`

If you want to simply change your textfield's font size , and not change it's font style at the same time , code below may be work : `

UITextField *yourTextField = [[UITextField alloc]init];
CGFloat yourSelectedFontSize = 14.0 ;
UIFont *yourNewSameStyleFont = [yourTextField.font fontWithSize:yourSelectedFontSize];
yourTextField.font = yourNewSameStyleFont ;

您需要注意的一件事是:更改文本字段的字体大小时,应始终注意文本字段视图的高度,保持文本文件的高度高于字体高度!

One thing you have to note is that : when you change your textfield's font size , you should always pay attention to your textfield view's height , keep your textfiled's height taller than your font height !

您可以尝试一下!

这篇关于如何以编程方式更改文本字段的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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