我想以編程方式更改按鈕影像和標題。當在情節提要上設計按鈕影像和標題(純文本)時,它居中沒問題。但是當我使用;
startButton.setImage(UIImage(named: "StartButton"), for: .normal)
startButton.setAttributedTitle(NSAttributedString(string: "START"), for: .normal)
以編程方式更改按鈕影像和標題。按鈕標題不以影像為中心。它看起來像是在影像的左側。
uj5u.com熱心網友回復:
這可能對您有所幫助。使用 setBackgroundImage 而不是 setImage
startButton.setBackgroundImage(UIImage(named: "StartButton"), for: .normal)
希望這個解決方案能解決你的問題??
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/359217.html
