开发者

Do I have to create view to draw rectagle?

开发者 https://www.devze.com 2023-03-27 23:12 出处:网络
I have MyViewController class which is subclass of UIViewController. I want to draw filled rect开发者_如何学Pythonagle on it\'s view.

I have MyViewController class which is subclass of UIViewController. I want to draw filled rect开发者_如何学Pythonagle on it's view. Do I have to create a new view, set it's background color and addSubview? What is the simplest way?


If you want a custom sized rectangle... yea pretty much what you described is the easiest.

UIView *rect = [[[UIView alloc] initWithFrame:CGRectMake(10,30,100,100)] autorelease];
[rect setBackgroundColor:[UIColor redColor]];

[[myViewController view] addSubview:rect];

Other possibilities exist though. You can go down into drawing stuff with like Quartz2D and what not. You could also make it so that when you draw the rect of the view, you draw a custom rectangle.

If you just want the entire view's background color set to a color:

[[myViewController view] setBackgroundColor:[UIColor redColor]];
0

精彩评论

暂无评论...
验证码 换一张
取 消