ios - SetImage 隐藏标题文本...无法使用背景图像,因为我需要 EdgeInsets

标签 ios objective-c swift

我正在尝试将文本添加到图像底部,但 setImage 隐藏了我的文本。

Top1.setImage(UIImage(named: "DefaultPic.jpg"), forState: UIControlState.Normal)
Top1.setTitle("#1", forState: UIControlState.Normal)
Top1.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
Top1.titleEdgeInsets = UIEdgeInsetsMake(20, 0, 0, 0);

我不能使用背景图像,因为我希望文本和图像之间有一个小间隙,而不必使用单独的 UILabel

最佳答案

Top1.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 20, 0);
Top1.titleEdgeInsets = UIEdgeInsetsMake(31, 0, 0, 0);

如果你想在image下放置title

关于ios - SetImage 隐藏标题文本...无法使用背景图像,因为我需要 EdgeInsets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32319107/

相关文章:

ios - Swift - 核心数据被覆盖

iphone - 不用 [[UIDevice] uniqueIdentifier] 安全实现三路和四路设备同步?

ios - 观察者是否被 Swift 单例永久保留?

swift - 更新 WatchKit 中的 Glance View

ios - 具有多个 TableView 键的 NSDictionary

ios - SwiftUI View 无需输入自动滚动到底部

iphone - 如何从另一个 View Controller 调用方法

arrays - Swift - 插入字符数组,功能解决方案

ios - 在 uitextfield 和 uitextview 上添加内部阴影

ios - 为什么 UIViewController.UIView 对子 UIViewLabel 的约束抛出错误 "Invalid pairing of layout attributes"?