up to now I have been using a if and else statement to define the size of objects that are displayed on iPhone or iPad, like for example:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown){
//For Portrait on iPhone
[self.navBar setFrame:CGRectMake(0.0 , 0.0, 320.0f, 44.0)];
} else if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
//For Landscape on iPhone
[self.navBar setFrame:CGRectMake(0.0 , 0.0, 480.0f, 44.0)];
}
} else {
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown){
//For Portrait on iPad
[self.navBar setFrame:CGRectMake(0.0 , 0.0, 768.0f, 44.0)];
} else if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
//For Landscape on iPad
[self.navBar setFrame:CGRectMake(0.0 , 0.0, 1024.0f, 44.0)];
}
}
But now I want to change it in order to make it a bit more dynamic. I am trying to use the following but there is no luck at all.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
Can anybody please help me on how to implement these two together? It seems that the way I mix them up is the problem. If anybody can give me a template or even a hint for that I will really appreciate it.
Thanks a lot
It seems like you’re overthinking this. Why not just: