简体   繁体   English

iOS和Xcode 6:按钮上的自动布局文本缩放

[英]iOS & Xcode 6: Auto Layout Text Scaling on a Button

I have a Today Extension with a button and UIImage. 我有一个带有按钮和UIImage的Today Extension。 The button and image scale and center themselves correctly except the button's text is not scaled. 按钮和图像本身会正确缩放和居中,除非按钮的文本未缩放。 I am writing this extension in Swift. 我正在用Swift编写此扩展。 I have tried these so far: 到目前为止,我已经尝试过这些:

myButton.titleLabel.adjustsFontSizeToFitWidth = true
myButton.adjustsFontSizeToFitWidth = true

Both return errors. 两者都返回错误。

Without seeing more code or the specific errors, the only thing I can see is that titleLabel is an optional. 在没有看到更多代码或特定错误的情况下,我唯一看到的是titleLabel是可选的。 As written, the compiler would show the error 'UILabel? does not have a member named 'adjustsFontSizeToFitWidth' 如所写,编译器将显示错误'UILabel? does not have a member named 'adjustsFontSizeToFitWidth' 'UILabel? does not have a member named 'adjustsFontSizeToFitWidth' . 'UILabel? does not have a member named 'adjustsFontSizeToFitWidth' Writing the line as myButton.titleLabel?.adjustsFontSizeToFitWidth = true should fix the error. 将行写为myButton.titleLabel?.adjustsFontSizeToFitWidth = true应该可以修复该错误。

Also, UIButton doesn't have a member named 'adjustFontSizeToFitWidth' so the second line would throw the same error as above. 另外,UIButton没有名为“ adjustFontSizeToFitWidth”的成员,因此第二行将引发与上述相同的错误。

Try fixing that error as indicated above and see if your AutoLayout issue works. 尝试按照上述指示修复该错误,然后查看自动布局问题是否可以解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM