まんマルのViewを作る方法のメモです。

ポイント

・正方形のUIView

・cornerRadius に1辺の半分の長さ

サンプルコード

※QuartzCoreを使う。

#import <QuartzCore/QuartzCore.h>

#import “ViewController.h”

@interface ViewController ()

@end

@implementation ViewController

– (void)viewDidLoad

{

    [super viewDidLoad];

    

    // 1. 正方形 100 x 100 View

    UIView *circle = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100.0, 100.0)];

    

    

    // cornerRadius 50 (1辺の半分の長さ) に設定

    circle.layer.cornerRadius = 50.0;

    

    

    // 表示

    circle.backgroundColor = [UIColor greenColor];

    [self.view addSubview:circle];

}

@end