开发者

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜