A UILabel has a Dynamic Type: Automatically Adjusts Font
check-box in the Attributes Inspector in Interface Builder.
Is there an equivalent in Interface Builder for automatically adjusting the font size of a UIButton, or does this have to be handled in code?
I'm using Xcode 9.0 beta 6, targeting iOS 11.
The Dynamic Type feature allows users to choose the size of textual content displayed on the screen. It helps users who need larger text for better readability. It also accommodates those who can read a smaller text, allowing more information to appear on the screen.
Dynamic Type is a feature that was introduced in iOS 7 allowing users to change the default font size used across iOS. It is intended predominantly to support visually impaired users but in practice there are many iOS users who simply prefer a smaller / larger reading size for a variety of reasons.
Change Font And Size Of UILabel In Storyboard XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
Apparently there isn't, but it's not very hard to fix. You can make an extension on UIButton
with an @IBInspectable
property:
extension UIButton {
@IBInspectable
var adjustsFontForContentSizeCategory: Bool {
set {
self.titleLabel?.adjustsFontForContentSizeCategory = newValue
}
get {
return self.titleLabel?.adjustsFontForContentSizeCategory ?? false
}
}
}
Now you can simply turn it on for every UIButton (or any of its subclasses).
Well there seems to be a way to do it in the Interface Builder only. I use Xcode version 11.5.
1. First set as usual a dynamic font type:
I choose Subhead
because according to this link it will be 15 pt height which was the font size I had previously set for the button.
2. Instead of setting the titleLabel.adjustsFontForContentSizeCategory
in code, you can set it in the "User Defined Runtime Attributes" section in Xcode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With