swift - 如何消除 UIButton 图像和 UIButton 边框之间的填充?

标签 swift uibutton padding uiedgeinsets

我想消除 UIButton 图像的顶部和 UIButton 的顶部边框以及 UIButton 图像的底部和 UIButton 的底部边框之间的间距(请参阅附图)。

我尝试使用以下代码,但没有成功:

newFileButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

        newFileButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

        newFileButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

非常感谢任何建议。

问候, 沙迪。

enter image description here

最佳答案

默认情况下,插图为零。要消除内部空间,请添加负插图。

newFileButton.imageEdgeInsets = UIEdgeInsets(top: -4, left: 0, bottom: -4, right: 0)

关于swift - 如何消除 UIButton 图像和 UIButton 边框之间的填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56534139/

相关文章:

ios - 使用 Firebase 累积角标(Badge)编号的任何方法?

Android - 如何在 ListView 或 ExpandableListView 中为 TextView 设置填充

swift - 如何展平可选的异构值数组

ios - Swift CloudKit 保存记录 "Error saving record"

ios - 检测用户何时停止触摸 UIButton

ios - UIButton 没有响应在自定义 UITableViewCell 中使用

html - 从我的 UL LI 中删除随机填充?

CSS:overflow-y 和 padding 调整

ios - iOS 8.3 中的调试 Realm

ios - 单击按钮时如何激活 UISearchDisplayController