按钮图像上的中心标题
Center title on the button image
我想以编程方式更改按钮图像和标题。当在故事板上设计按钮图像和标题(普通)时,它居中没有问题。但是当我使用;
startButton.setImage(UIImage(named: "StartButton"), for: .normal)
startButton.setAttributedTitle(NSAttributedString(string: "START"), for: .normal)
以编程方式更改按钮图像和标题。按钮标题未居中于图像。它看起来像在图像的左侧。
这可能对您有所帮助。
使用 setBackgroundImage 而不是 setImage
startButton.setBackgroundImage(UIImage(named: "StartButton"), for: .normal)
希望这个解决方案能解决您的问题
我想以编程方式更改按钮图像和标题。当在故事板上设计按钮图像和标题(普通)时,它居中没有问题。但是当我使用;
startButton.setImage(UIImage(named: "StartButton"), for: .normal)
startButton.setAttributedTitle(NSAttributedString(string: "START"), for: .normal)
以编程方式更改按钮图像和标题。按钮标题未居中于图像。它看起来像在图像的左侧。
这可能对您有所帮助。 使用 setBackgroundImage 而不是 setImage
startButton.setBackgroundImage(UIImage(named: "StartButton"), for: .normal)
希望这个解决方案能解决您的问题