我无法找到一种方法,使按钮看起来如下图所示。
图标应该比按钮大。
我已经厌倦了,但它不起作用:
let image = UIImage(named: "CircleForButtonCountries")
goToCoutriesButtonMain.imageView?.contentMode = UIViewContentMode.scaleAspectFit
goToCoutriesButtonMain.setImage(image, for: UIControlState.normal)
答案 0 :(得分:0)
试试此代码
let image = UIImage(named: "CircleForButtonCountries")
goToCoutriesButtonMain.imageView?.contentMode =
UIViewContentMode.scaleAspectFit
goToCoutriesButtonMain.setBackgroundImage(image, for: UIControlState.normal) // use setBackgroundImage instead of setImage
答案 1 :(得分:0)
在Swift 5中工作:
yourButton.clipsToBounds = true
yourButton.contentMode = .scaleAspectFill
yourButton.setBackgroundImage(UIImage(named: "yourImage"), for: .normal)