Swift 3按钮文本自动调整大小 [英] Swift 3 Button text auto resizing

查看:101
本文介绍了Swift 3按钮文本自动调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有基于设备自动调整大小的按钮,我想知道如何使按钮文本自行调整大小,就像具有最小尺寸或比例的UILable一样。

So I have buttons that auto resize based on device and I was wondering how I could make the button text resize on its own like a UILable with the minimum size or scale.

推荐答案

正如Matt所说UIButton标题与UILabel一起显示,您可以使用minimumScaleFactor和adjustsFontSizeToFitWidth等属性,这样字体就会根据可用的大小和内容调整大小已经。

As Matt said above UIButton title is displayed with UILabel, you could use properties such as minimumScaleFactor and adjustsFontSizeToFitWidth, such that the font resizes based on the size that is available and content that it has.

button.titleLabel.minimumScaleFactor = 0.5;
button.titleLabel.adjustsFontSizeToFitWidth = true;

这篇关于Swift 3按钮文本自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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