我正在配置我的表格 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/