Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting marginWidth between Icon and Title doesn't work #151

Open
LanceSamaria opened this issue Dec 13, 2018 · 4 comments
Open

Setting marginWidth between Icon and Title doesn't work #151

LanceSamaria opened this issue Dec 13, 2018 · 4 comments

Comments

@LanceSamaria
Copy link

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
Copy link
Author

LanceSamaria commented Dec 19, 2018

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

@Adarkas2302
Copy link

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.

@LanceSamaria
Copy link
Author

LanceSamaria commented Mar 2, 2019

@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

@Adarkas2302
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants