在图标和标题之间设置 DLRadioButton marginWidth

Set DLRadioButton marginWidth between icon and title

在我升级​​到 Swift 4.2 - Xcode 10.1 之前,我使用的 DLRadioButtonicontitle 之间有均匀的间距。我从不设置间距,一切正常。升级后 icontitle 重叠

cocoapod for it 表示它使用 kdefaultmarginwidth

的默认 marginWidth

我尝试将代码中的 marginWidth 设置为任何肯定会像 50.0 这样增加间距的东西,但重叠仍然存在。我在某处读到 kdefaultmarginwidth 间距是 5.0

如何调整间距?

代码:

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
}

这是一个不稳定的修复程序,但它现在有效,因为我尝试的其他所有方法都不起作用。在 saleButton 闭包中,我必须在设置标题字符串之前添加 4 个空格:

我改变了这个:

button.setTitle("Sale", for: .normal)

至此,重叠部分现已消失

// there are 4 empty spaces in front of the word Sale
button.setTitle("    Sale", for: .normal)

这是下图: