I am doing some simple testing of adding CALayer to a UIView. In my main controller class of an iPhone 4 app, I implemented the viewDidLoad
method as such:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%s", __PRETTY_FUNCTION__);
CALayer* ca = [[CALayer alloc] init];
[ca setBounds:self.view.bounds];
[ca setBackgroundColor:[[UIColor blueColor] CGColor]];
[self.view.layer addSublayer:ca];
}
The blue background only occupy 1/4 of the screen.
I wonder if it is because I did not take retina display into consideration? What is the best practice in this situation?
Added these debug messages:
NSLog(@"frame w:%f h:%f", self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"bounds w:%f h:%f", self.view.bounds.size.width, self.view.bounds.size.height);
Output:
frame w:320.000000 h:460.000000
bounds w:320.000000 h:460.000000
setContentsScale
has no effect
[ca setContentsScale:[[UIScreen mainScreen] scale]];
However, if I use
[ca setFrame:self.view.bounds];
it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With