DLRadioButton
DLRadioButton copied to clipboard
Setting marginWidth between Icon and Title doesn't work
Before I upgraded to Swift 4.2 - Xcode 10.1 the DLRadioButton I used had an even spacing between the icon and the title. I never set the spacing and everything worked fine. After the upgrade and pod upgrade the icon and the title overlaps.
I tried to set the marginWidth in code to anything that would definitely add spacing like 50.0 but the overlap stays.
How can I fix the spacing?
let saleButton: DLRadioButton = {
let button = DLRadioButton(type: .custom)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Sale", for: .normal)
button.setTitleColor(UIColor.lightGray, for: .normal)
button.marginWidth = 50.0 // I tried 5.0, 10.0, 20.0, even 100.0 but nothing
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(saleButton)
// constraints get set
}
This is a choppy fix but it works for because everything else I tried didn't work. Inside the saleButton closure, I had to add 4 empty spaces before I set the string for the title:
I changed this:
button.setTitle("Sale", for: .normal)
to this and the spacing is now correct
button.setTitle(" Sale", for: .normal) // there are 4 spaces
I have the same problem. It seems that it is not influenced by the version of DLRadioButton but by the iOS Version. With the same build in iOS 11, the marginWidth seems to work correctly.
@Adarkas2302 Yeah I noticed the same thing, it worked fine for iOS 11.
Try something like this:
let systemVersion = UIDevice.current.systemVersion
if systemVersion.contains("12.") {
button.setTitle(" Sale", for: .normal) // there are 4 spaces for iOS 12 or greater
} else {
button.setTitle("Sale", for: .normal) // this is how it should normally work
}
Of course if there is anyVersionLessThenTwelve.12.x this will be true
Thanks for the help, I did it like this already.