我想以编程方式更改按钮图像和标题。当在故事板上设计按钮图像和标题(普通)时,它居中没有问题。但是当\xc4\xb1使用时;
\n startButton.setImage(UIImage(named: "StartButton"), for: .normal)\n startButton.setAttributedTitle(NSAttributedString(string: "START"), for: .normal)\n
Run Code Online (Sandbox Code Playgroud)\n以编程方式更改按钮图像和标题。按钮标题未位于图像中心。看起来它位于图像的左侧。
\n这可能对你有帮助。使用 setBackgroundImage 而不是 setImage
startButton.setBackgroundImage(UIImage(named: "StartButton"), for: .normal)
Run Code Online (Sandbox Code Playgroud)
希望这个解决方案能够解决您的问题
归档时间: |
|
查看次数: |
137 次 |
最近记录: |