Reputation: 1614
How to make the view's background color change base on the size of view? I can re-size the view but seem the background color not change, it's fixed.
color = [view backgroundColor];
[view setBackgroundColor:[UIColor clearColor]];
[view setFrame:rect];
[view setBackgroundColor:color];
Upvotes: 0
Views: 336
Reputation: 1320
Implement the setFrame Method of the View then only Your Change background color will be called when ever you change the size of View....
Make subclass of a UIView and implement setFrame Method.
-(void)setFrame:(CGRect)frame{
self = [super setFrame:frame];
self.backgroundColor = [UIColor redColor];
//Put any condition here for specific background color using frame property of view
}
Upvotes: 0
Reputation: 2357
You have set the background color of view to ClearColor
, So it's not being changed.
Try,
color = [view backgroundColor];
[view setBackgroundColor:[UIColor clearColor]];
[view setFrame:rect];
// here you need to set the
color = [UIColor redColor]; // or the color you want to change
[view setBackgroundColor:color];
Upvotes: 2