Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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
Iphone 无法在滚动视图中显示控件外接程序';使用自动布局创建内容视图_Iphone_Ios_Ipad_Nslayoutconstraint_Autolayout - Fatal编程技术网

Iphone 无法在滚动视图中显示控件外接程序';使用自动布局创建内容视图

Iphone 无法在滚动视图中显示控件外接程序';使用自动布局创建内容视图,iphone,ios,ipad,nslayoutconstraint,autolayout,Iphone,Ios,Ipad,Nslayoutconstraint,Autolayout,我是新的自动布局部分。我正在用scroll编程创建一个视图,但我无法在scroll视图的内容视图中添加控件 这是我的密码: -(void)setConstraints { UIScrollView *scrollView = [UIScrollView new]; [scrollView setTranslatesAutoresizingMaskIntoConstraints:NO]; scrollView.backgroundColor = [UIColor gree

我是新的自动布局部分。我正在用scroll编程创建一个视图,但我无法在scroll视图的内容视图中添加控件

这是我的密码:

-(void)setConstraints
{

    UIScrollView *scrollView = [UIScrollView new];
    [scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
    scrollView.backgroundColor = [UIColor greenColor];

    UIView *contentView = [UIView new];
    [contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
    contentView.backgroundColor = [UIColor redColor];

    UILabel *lableTitle = [UILabel new];
    lableTitle.text = @"Registration";
    [lableTitle setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSLayoutConstraint *layoutLableTop = [NSLayoutConstraint constraintWithItem:lableTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:20];
    [self.view  addConstraint:layoutLableTop];

    NSLayoutConstraint *layoutLableCenterX = [NSLayoutConstraint constraintWithItem:lableTitle attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    [self.view addConstraint:layoutLableCenterX];

    [contentView  addSubview:lableTitle];
    [scrollView addSubview:contentView];

    [self.view addSubview:scrollView];


}

显示的视图只是白色屏幕。我做错了什么?

例如,必须为尺寸添加约束

[self.view addConstraint:
 [NSLayoutConstraint constraintWithItem:scrollView
                              attribute:NSLayoutAttributeWidth
                              relatedBy:NSLayoutRelationEqual
                                 toItem:contentView
                              attribute:NSLayoutAttributeWidth
                             multiplier:1
                               constant:200]];
[self.view addConstraint:
 [NSLayoutConstraint constraintWithItem:scrollView
                              attribute:NSLayoutAttributeHeight
                              relatedBy:NSLayoutRelationEqual
                                 toItem:contentView
                              attribute:NSLayoutAttributeHeight
                             multiplier:1
                               constant:200]];

抱歉@jaba,但是它显示了视图。你在哪里调用该方法?它应该显示300-300大小的绿色视图。是的,它现在显示的是scrollview@jaba。但我仍然需要做更多的事情。之后我会告诉你最新情况。如果我找不到路。