2
3

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 5 years have passed since last update.

UIButtonなどの角を丸くする方法

2
Posted at

デフォルトではボタンの角が四角なため、丸くします。

ViewController.swift
class ViewController: UIViewController {

	var tapButton: UIButton = UIButton()//角を丸くするボタン
	
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let height = self.view.frame.height
        let width = self.view.frame.width
	
		tapButton.frame = CGRect(x: 0, y: CGRectGetMinY(myLabel.frame), width: width / 4, height: height / 6 - 10)
        tapButton.backgroundColor = UIColor.grayColor()
        tapButton.layer.position.x = (width / 4) * 3
 
        // 以下2行が丸くする処理       
        tapButton.layer.cornerRadius = 20.0 //どれくらい丸くするのか
        tapButton.layer.masksToBounds = true //viewに丸くする許可を出す
        
        //tapButtonの表示
        self.view.addSubview(tapButton)
    }
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?