DLRadioButton icon indicating copy to clipboard operation
DLRadioButton copied to clipboard

Setting marginWidth between Icon and Title doesn't work

Open LanceSamaria opened this issue 6 years ago • 4 comments

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.

fullsizerender

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
}

LanceSamaria avatar Dec 13 '18 23:12 LanceSamaria

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

screen shot 2018-12-18 at 8 32 00 pm

LanceSamaria avatar Dec 19 '18 01:12 LanceSamaria

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 avatar Mar 01 '19 14:03 Adarkas2302

@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

LanceSamaria avatar Mar 02 '19 04:03 LanceSamaria

Thanks for the help, I did it like this already.

Adarkas2302 avatar Mar 04 '19 10:03 Adarkas2302