Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取要在Objective-C的文本字段中显示的屏幕大小结果_Ios_Objective C - Fatal编程技术网

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

Ios 获取要在Objective-C的文本字段中显示的屏幕大小结果,ios,objective-c,Ios,Objective C,我认为这真的很简单,但是如何在Objective-C中的文本字段中显示屏幕大小的结果呢?我可以在NSLog中获得它,如下所示: CGRect rect = [[UIScreen mainScreen] bounds]; CGFloat screenHeight = rect.size.height; NSLog(@"%f",screenHeight); 但不是在文本字段中 有什么想法吗?您可以使用stringWithFormat方法将CGFloat转换为NSString,并可以设置为Text

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

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

NSLog(@"%f",screenHeight);
但不是在文本字段中


有什么想法吗?

您可以使用stringWithFormat方法将CGFloat转换为NSString,并可以设置为TextField。代码为fllow:

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

希望对您有所帮助。

您知道如何设置文本字段的文本吗?您知道如何将
CGFloat
转换为
NSString