UIButton的图像和标题边缘以编程方式在Swift中进行插入

时间:2016-11-25 10:59:02

标签: ios swift uibutton uiedgeinsets

我正在以编程方式设置两个UIButtons,如下所示:

enter image description here

我试图将图像和文本插入设置为按钮中的相同,但不知何故,左按钮的图像与右图像的位置不同。 我对UIButton类有这个扩展:

func setTextAndImageForButton(spacing: CGFloat) {
        let insetAmount = spacing / 2
        imageEdgeInsets = UIEdgeInsets(top: 8, left: 4, bottom: 8, right: insetAmount)
        titleEdgeInsets = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: -insetAmount)
        contentEdgeInsets = UIEdgeInsets(top: insetAmount, left: 0, bottom: insetAmount, right: insetAmount*1.5)
    }

据我所知,当我为图像,文本和整个内容设置插图时,它应该位于两个实例的相同位置。

在我在代码中设置后,插图是否会以某种方式覆盖?

0 个答案:

没有答案