I have text on a small button that isn't important, and I want it to not change with dynamic text size. I have done that in the UIButton
config, but it seems that the width of the label seems to get smaller and start to clip my text that isn't changing size. Previously it was forcing it to wrap and I could force it to clip with titleLineBreakMode
but that's just a band-aid. What's going on here?
Here's my button config:
var config = UIButton.Configuration.plain()
config.titleLineBreakMode = .byClipping // Prevents word wrap, but just a band-aid
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var attributes = incoming
attributes.font = .systemFont(ofSize: 16)
return attributes
}
button.configuration = config
Here's my button with Large dynamic text size.
Here's my button with Accessibility 3 text size.
I have text on a small button that isn't important, and I want it to not change with dynamic text size. I have done that in the UIButton
config, but it seems that the width of the label seems to get smaller and start to clip my text that isn't changing size. Previously it was forcing it to wrap and I could force it to clip with titleLineBreakMode
but that's just a band-aid. What's going on here?
Here's my button config:
var config = UIButton.Configuration.plain()
config.titleLineBreakMode = .byClipping // Prevents word wrap, but just a band-aid
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var attributes = incoming
attributes.font = .systemFont(ofSize: 16)
return attributes
}
button.configuration = config
Here's my button with Large dynamic text size.
Here's my button with Accessibility 3 text size.
Share Improve this question asked Feb 5 at 19:27 teradylteradyl 2,8021 gold badge31 silver badges39 bronze badges 2 |1 Answer
Reset to default 0rather than adding it that like do this and apply it later than it works
var config = UIButton.Configuration.plain()
config.minimumSize = CGSize(width: 100, height: 40) // Adjust as needed
let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 16)
]
let attributedTitle = NSAttributedString(string: "300 text", attributes: attributes)
let button = UIButton(configuration: config)
button.setAttributedTitle(attributedTitle, for: .normal)
button.setContentHuggingPriority(.required, for: .horizontal)
button.setContentCompressionResistancePriority(.required, for: .horizontal)
button.titleLabel.adjustsFontForContentSizeCategory = false
. – HangarRash Commented Feb 5 at 19:39