swift - UIButton 中的图像和标题

标签 swift uibutton

我正在配置我的表格 View 单元格,如下所述。它有效,但问题是标题“已关闭”之前有不需要的空间,因为我要删除图像。如何删除不需要的空格,以便我的“已关闭”标题居中?

if (condition) {
  self.myButton.setImage(UIImage(named: "activeImage"), forState: .Normal)
  self.myButton.setTitle("Active", forState: .Normal)
} 
else {
  self.myButton.setImage(nil, forState: .Normal)
  self.myButton.setTitle("Closed", forState: .Normal)
}

最佳答案

在其他情况下你可能会错过这个

self.myButton.contentHorizontalAlignment = .Center
self.myButton.contentVerticalAlignment = .Center

关于swift - UIButton 中的图像和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35907615/

相关文章:

ios - BOOL UIButton 上的按钮选择

events - UIButton在编码阶段的事件 Hook 内部修饰?

ios - 如何在自动布局中使用 UITableViewCell 的动态高度并在隐藏底部 View 时将其他 View 向上移动?

ios - 自动调整 UICollectionView 标题

ios - 自定义 UITableViewCell accessoryView 按钮在真实设备上不可见

ios - UIButton 此类与键的键值代码不兼容

iphone - 以编程方式创建按钮

ios - 单击时如何避免单元格分隔符消失

ios - 无法正确定位 UIActivityIndi​​catorView

ios - UITableViewController 的子类和变量初始化。 iOS、环球银行金融电信协会