0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UIButton の角丸とカラー周りを、Swiftで。

Last updated at Posted at 2021-04-01

#swift で、UIButtonを象るタグたち。
####まずアウトレット接続する方法と、シート内で作る方法の二通りがあり、

let button1 = UIButton()
button1.frame = CGRect(x: 20, y: self.view.frame.size.height/2-22, width: self.view.frame.size.width-40, height: 44)
button1.setTitle("My Button", for: .normal)
button1.setTitleColor(.brown, for: .normal)
button1.backgroundColor = .black
button1.layer.cornerRadius = 15
button1.layer.borderWidth = 3
button1.layer.borderColor = .purple
self.view.addSubView(button1)

最下段のサブビューのくだりは、小のシート上で簡潔するボタンメイク、アウトレット接続の場合は、いらない。
また、シート全体で使う場合は、イニシャライズ(初期化)を、

import UIKit

class ViewController: UIViewController {
   var button1 = UIButton()
   override viewDidLoad() {

   }
}

とViewDidLoad() のそとで定義することが必要。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?