UIScrollView contentSize not working

前端 未结 15 1587
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 06:18

I put a UIScrollView in my nib\'s view, and linked it to a an IBOutlet property.

Now, when I do this in my viewDidLoad

15条回答
  •  萌比男神i
    2020-11-28 07:16

    If you are using AutoLayout a really easy way to set the contentSize of a UIScrollView is just to add something like this:

    CGFloat contentWidth = YOUR_CONTENT_WIDTH;
    
    NSLayoutConstraint *constraintWidth = 
     [NSLayoutConstraint constraintWithItem:self.scrollView 
                                  attribute:NSLayoutAttributeTrailing 
                                  relatedBy:NSLayoutRelationEqual 
                                     toItem:self.scrollView 
                                  attribute:NSLayoutAttributeLeading 
                                 multiplier:1 
                                   constant:contentWidth];
    
    [self.scrollView addConstraint:constraintWidth];
    

提交回复
热议问题