简体   繁体   English

动态设置自动布局以在iOS中滚动视图

[英]Set auto layout dynamically to scroll view in iOS

i am creating scroll view dynamically now i want to set auto layout for that i implemented following code to set auto layout but its not working at all. 我现在正在动态创建滚动视图,我想为此设置自动布局,我实现了以下代码来设置自动布局,但它根本不起作用。

   - (void)viewDidLoad
   {
   [super viewDidLoad];
        self.navigationItem.title=@"Insta SMS Collection";
        scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];


    [self.view addSubview:scrollView];
    scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    NSDictionary *views = @{@"scrollView":scrollView};
    [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:  
    [scrollView]"
    options:kNilOptions
    metrics:nil
    views:views;
    [self.view addSubview:scrollView];
    }

add horizontal and vertical autolayout. 添加水平和垂直自动布局。

[self.view addSubview:scrollView];
NSDictionary *dictScrollConst = NSDictionaryOfVariableBindings(scrlView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrlView]|" options:0 metrics:nil views:dictScrollConst]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrlView]|" options:0 metrics:nil views:dictScrollConst]];

Maybe this will help you. 也许这会对您有所帮助。

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

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