Objective-C

[objc][memo] さっくと、四角いUIView 丸いUIViewを作る。

More than 3 years have passed since last update.

サクッとUIView作って表示確認したいとき

//------------------------------
// 四角のUIView
//------------------------------
UIView * square = [[UIView alloc] initWithFrame:CGRectMake(35,55,10,10)];
square.backgroundColor = [UIColor blueColor] ;
[self.view addSubview:square];


//------------------------------
// 円のUIView
//------------------------------
float r = 12.0f;
float x = 5.0f;
float y = 5.0f;
UIView *circle = [[UIView alloc] initWithFrame:CGRectMake(x,y,r,r)];
circle.alpha = 0.5;
circle.layer.cornerRadius = r*0.5;
circle.backgroundColor = [UIColor blueColor];
[self.view addSubview:circle];