「Swift」UIButtonの画像、タイトル、背景色を設定するサンプル

書式
button.setImage(xx)
button.setTitle(xx)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
func initView() -> Void {
var button:UIButton = UIButton(frame: CGRectMake(100, 150, 100, 100))
button.setImage(UIImage(named: "button.png"), forState: UIControlState.Normal)
button.setTitle("button", forState: UIControlState.Normal)
button.backgroundColor = UIColor.blueColor()
self.view.addSubview(button)
}
func initView() -> Void { var button:UIButton = UIButton(frame: CGRectMake(100, 150, 100, 100)) button.setImage(UIImage(named: "button.png"), forState: UIControlState.Normal) button.setTitle("button", forState: UIControlState.Normal) button.backgroundColor = UIColor.blueColor() self.view.addSubview(button) }
func initView() -> Void {
   var button:UIButton = UIButton(frame: CGRectMake(100, 150, 100, 100))

   button.setImage(UIImage(named: "button.png"), forState: UIControlState.Normal)
   button.setTitle("button", forState: UIControlState.Normal)
   button.backgroundColor = UIColor.blueColor()

   self.view.addSubview(button)
}

 

Swift

Posted by arkgame