开发者

How can i simplify UIScreen width?

开发者 https://www.devze.com 2023-01-05 04:22 出处:网络
how can i simplify that code in one line? CGRect screen = [[UIScreen mainScreen] bounds]; NSLog(开发者_JAVA百科@\"%@\",screen.size.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

精彩评论

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