我正试图在一个按钮上显示一个图像,我正在通过按钮获得图像的蓝色打印,我到目前为止已尝试过 –
override func viewDidLoad() { super.viewDidLoad() var birdTexture1 = UIImage(named: "fish.png") as UIImage button1.frame = CGRectMake(100,10,50,150) button1.setImage(birdTexture1,forState: .Normal) button1.setTitle("Testing",forState: UIControlState.Normal) button1.addTarget(self,action: "btnAction:",forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(button1) // Do any additional setup after loading the view,typically from a nib. }
但实际图像是这样的 –
我认为您的UIButton需要是UIButtonTypeCustom类型,而不是UIButtonTypeSystem.您要么构造它,要么需要在界面构建器中更新UIButton的属性.
原文链接:https://www.f2er.com/swift/318626.html