UILabelで角丸が付いたものや、パディングしたいと思っても若干面倒そう。
↓
UILabelを角丸にする&パディングを設定する方法
var buttonAsLabel = UIButton(frame: CGRectMake(100, 100, 200, 50))
//テキスト入れる
buttonAsLabel.setTitle("ラベルの代わりに", forState: .Normal)
//角丸を指定できる
buttonAsLabel.layer.cornerRadius = 15
//テキストのカラー
buttonAsLabel.setTitleColor(UIColor.whiteColor(), forState: .Normal)
//背景カラー
buttonAsLabel.backgroundColor = UIColor.orangeColor()
//titleEdgeInsetsでpaddingができる
buttonAsLabel.titleEdgeInsets.left = 30
//ボタンとしての機能を停止→iOS7ではテキストが表示されなくなったのでやめます。
//buttonAsLabel.enabled = false
self.view.addSubview(buttonAsLabel)
ちなみに「アイコン+文字」みないなのもUIButtonが便利。
var buttonAsLabel2 = UIButton(frame: CGRectMake(100, 300, 200, 50))
//画像を設定
buttonAsLabel2.setImage(UIImage(named: "apple.png"), forState: .Normal)
buttonAsLabel2.setTitle("サンプルテキスト", forState: .Normal)
buttonAsLabel2.setTitleColor(UIColor.blackColor(), forState: .Normal)
//ボタンとしての機能を停止→iOS7ではテキストが表示されなくなったのでやめます。
// buttonAsLabel2.enabled = false
self.view.addSubview(buttonAsLabel2)