How can i simplify UIScreen width?
how can i simplify that code in one line?
CGRect screen = [[UIScreen mainScreen] bounds];
NSLog(开发者_JAVA百科@"%@", screen.size.width);
Thanks for your time.
This statement will cause an exception, or should:
NSLog(@"%@", screen.size.width);
The width
property returns a CGFloat
. You would need to change your log statement to:
NSLog(@"%f", screen.size.width);
If you want everything on one line:
NSLog(@"%f", [[[[UIScreen mainScreen] bounds] size] width]);
I would suggest:
NSLog(@"%1.0f", [UIScreen mainScreen].bounds.size.width);
To get both height and width you can use NSStringFromCGSize:
NSLog(@"%@", NSStringFromCGSize([UIScreen mainScreen].bounds.size));
精彩评论