Swift:图像大于按钮的按钮

标签 swift uibutton

我想不出使按钮看起来像下图所示的方法。

image of the button

图标应该比按钮大。

我已经厌倦了这个,但它不起作用:

let image = UIImage(named: "CircleForButtonCountries")
goToCoutriesButtonMain.imageView?.contentMode = UIViewContentMode.scaleAspectFit
goToCoutriesButtonMain.setImage(image, for: UIControlState.normal)

最佳答案

试试这段代码

let image = UIImage(named: "CircleForButtonCountries")
goToCoutriesButtonMain.imageView?.contentMode = 
UIViewContentMode.scaleAspectFit
goToCoutriesButtonMain.setBackgroundImage(image, for: UIControlState.normal)  // use setBackgroundImage instead of setImage 

关于Swift:图像大于按钮的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50030794/

相关文章:

ios - 一个 UIButton 上的两个控件事件

ios - UIButton 用户定义的运行时属性不起作用

swift - 从一个 UINavigationController 转到另一个 UINavigationController (Swift iOS 9, xcode 7)

ios - Tableview 搜索栏未正确返回 detailTextLabel(Xcode - Swift)

ios - 如何追加数组。或者我如何将模型转换为 nsmuttable 数组

ios - UIButton 异常 : Unable to set title for a custom button type

ios - 为什么我的 UIButton 会影响 Swift 中的 UIImageView?

ios - 调用自定义 View 时 UIButton 不可单击

Swift/Parse - 如何在应用程序首次打开时预加载数据,这样我就不会?

macos - 在 OSX 上的 Swift 主窗口中设置自定义 View