Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 7下,如何创建UITextView';s的高度取决于运行应用程序的设备类型(4英寸屏幕与3.5英寸屏幕)_Ios_Objective C_Uiview_Ios7_Uitextview - Fatal编程技术网

在iOS 7下,如何创建UITextView';s的高度取决于运行应用程序的设备类型(4英寸屏幕与3.5英寸屏幕)

在iOS 7下,如何创建UITextView';s的高度取决于运行应用程序的设备类型(4英寸屏幕与3.5英寸屏幕),ios,objective-c,uiview,ios7,uitextview,Ios,Objective C,Uiview,Ios7,Uitextview,我有一个UITextView,它应该消耗屏幕的高度,减去导航栏和键盘的高度(当视图加载时,键盘出现)。显然,在4英寸的设备上,这意味着文本视图应该稍微高一点。在Interface Builder中,是否可以使高度与设备相关 如果没有,我可以用代码来做吗?是否可以在没有自动布局约束的情况下执行此操作?您需要在代码中执行此检查,您可以使用下面的Macor来检查设备: #define IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 5

我有一个UITextView,它应该消耗屏幕的高度,减去导航栏和键盘的高度(当视图加载时,键盘出现)。显然,在4英寸的设备上,这意味着文本视图应该稍微高一点。在Interface Builder中,是否可以使高度与设备相关


如果没有,我可以用代码来做吗?是否可以在没有自动布局约束的情况下执行此操作?

您需要在代码中执行此检查,您可以使用下面的Macor来检查设备:

#define IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
然后:

是的,您可以使用两个自动布局约束来实现这一点,这是实现这一点的最佳实践,请检查以下问题:


使用自动布局约束将非常容易做到这一点。不使用它有什么特殊原因吗?

您可以使用支柱和弹簧。但自动布局是新的热点


离开null的答案:

我假设您将此UITextView放置在UIViewController中

可以在运行时设置UITextView的框架

在viewDidLoad中:

-(void)viewDidLoad {

    UITextView *textView = [[UITextView alloc] init];

    //216 is the height of the keyboard, 20 is the height of the status bar
    if (isiPhone5) {
        CGRect frame = CGRectMake(0, self.navigationBar.frame.size.height + 20, self.frame.size.width, 568-216); 
        [textView setFrame:frame];
    }
    else {
        CGRect frame = CGRectMake(0, self.navigationBar.frame.size.height + 20, self.frame.size.width, 480-216); 
        [textView setFrame:frame];
    }


}

不,我只是好奇有没有简单的方法。我假设我在代码中调整检测设备并相应地调整常数?
-(void)viewDidLoad {

    UITextView *textView = [[UITextView alloc] init];

    //216 is the height of the keyboard, 20 is the height of the status bar
    if (isiPhone5) {
        CGRect frame = CGRectMake(0, self.navigationBar.frame.size.height + 20, self.frame.size.width, 568-216); 
        [textView setFrame:frame];
    }
    else {
        CGRect frame = CGRectMake(0, self.navigationBar.frame.size.height + 20, self.frame.size.width, 480-216); 
        [textView setFrame:frame];
    }


}