LoginSignup
12
14

More than 5 years have passed since last update.

UIView(写真やラベルやView)の角を丸める方法

Last updated at Posted at 2015-10-31

今回行うこと

  1. ラベルを貼る
  2. 角を丸めるコードを書く
  3. 実行結果の確認

  1. ラベルを貼る
    StoryBoardにUILabelを貼る

    ViewControllerにUILabelに関連付けする
    スクリーンショット 2015-10-31 18.23.18.png

  2. 角を丸めるコードを書く


ViewController.swift

//
//  ViewController.swift
//  TestProject
//
//  Created by 坂本 大介 on 10/31/15.
//  Copyright © 2015 Daisuke Sakamoto. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var testLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        //丸める半径の指定
        testLabel.layer.cornerRadius = 20;

        //丸める許可
        testLabel.clipsToBounds = true;

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

3. 実行結果の確認

スクリーンショット 2015-10-31 18.28.15.png

まとめ

簡単に丸めることができましたね
この丸め方はLayerクラスをもつUIImageView,UIViewなどいろいろなところで活用できます!

12
14
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
12
14