繁体   English   中英

获取屏幕大小的结果以显示在 Objective-C 中的文本字段中

[英]Get result of screen size to display in text field in Objective-C

我认为这真的很简单,但是如何在 Objective-C 的文本字段中显示屏幕大小的结果? 我可以在 NSLog 中获取它,如下所示:

CGRect rect = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = rect.size.height;

NSLog(@"%f",screenHeight);

但不在文本字段中。

有任何想法吗?

您可以使用 stringWithFormat 方法将 CGFloat 转换为 NSString ,并且可以设置为 TextField.Code is flow:

 CGRect rect = [[UIScreen mainScreen] bounds];
 CGFloat screenHeight = rect.size.height;
 UITextField *textFiled = //------ some code----
 NSString *str = [NSString stringWithFormat:@"%lf",screenHeight];
 textFiled.text =str;

希望能帮到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM