Im learning iOS. I've been reading Apple's View programming guide. I did the followings to try out content mode:
- I dragged a uiview into storyboard and made it my CustomView class.
- Then i changed the content mode to be left and set the background color to be pink color.
- Then there's a button that just simply changes the custom view's width and height to be 1.5 times bigger.
Now, i found an interesting thing:
I run this, and click the button, then:
- Case 1: If i override the draw rect method
Then the appearance of the view shifted down
- Case 2: Without overriding the draw rect method drawRect: not overrided
The size actually increased
After doing some search online and look into Apple's document, i couldnt any relavent things except one question mention that this might have something to do with drawLayer:inContext: behave differently if override the drawRect:
Does anyone know what is going on here?
(sorry about the formatting, this is a new account and i can't post more than 2 links.)
CODE: For the CustomView, just either override drawRect or without it.
#import "CustomView.h"
@implementation CustomView
- (void)drawRect:(CGRect)rect{
//Do nothing, for case 2 i just commented out this method.
}
@end
For Changing the frame of customView:
- (IBAction)changeBound:(id)sender {
self.customView.frame = CGRectMake(self.customView.frame.origin.x, self.customView.frame.origin.y, self.customView.frame.size.width * 1.5, self.customView.frame.size.height * 1.5);
}