0

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];
    }
iYoung
  • 3,596
  • 3
  • 32
  • 59
  • why you are adding scrollview two times? and you don't need to set frame while using autolayout. – ChintaN -Maddy- Ramani Oct 17 '14 at 05:30
  • possible duplicate of [Auto layout UIScrollView with subviews with dynamic heights](http://stackoverflow.com/questions/16825189/auto-layout-uiscrollview-with-subviews-with-dynamic-heights) – iYoung Oct 17 '14 at 05:34

1 Answers1

1

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.

ChintaN -Maddy- Ramani
  • 5,156
  • 1
  • 27
  • 48