gpt4 book ai didi

iphone - 如何在iPhone应用程序中实现UIButton/UILabel 'padding'

转载 作者:行者123 更新时间:2023-12-03 18:09:27 25 4
gpt4 key购买 nike

我的 iPhone 应用程序中有各种需要填充的 View ,例如文本左对齐的自定义 UIButton 和具有背景颜色的 UILabel。

这可能是一个非常愚蠢的问题,但是我如何应用“填充”将文本移出左侧边缘?

我厌倦了使用边界等但没有成功。

我知道我可以为我的 UILabel 创建一个具有背景颜色的包装 View ,但这似乎有点矫枉过正。

非常感谢。

最佳答案

我正在使用自动布局。对我有用的解决方案是设置 UIButtoncontentEdgeInsets

对象

button.contentEdgeInsets = UIEdgeInsetsMake(0.0f, 30.0f, 0.0f, 30.0f);

swift

button.contentEdgeInsets = UIEdgeInsets(top: 0.0, left: 30.0, bottom: 0.0, right: 30.0)

关于iphone - 如何在iPhone应用程序中实现UIButton/UILabel 'padding',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3052731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com