jimbob
jimbob

Reputation: 3298

Scrollview will not scroll even with larger contentsize

Got a strange problem which I dont understand.

I set the content size to a CGSize I created called newSize. I am adding buttons in a row in the UIScrollView that goes outside of the frame of the scrollview and changing the content size to match the new width + 400 for insurance.

    newSize.width = contentSizeWidth+400;

    NSLog(@"newSize width: %f", newSize.width);

    [_scrollViewOutlet addSubview:button];

    [_scrollViewOutlet setContentSize:newSize];

    NSLog(@"scrollviewOutlet Content Width: %f", _scrollViewOutlet.contentSize.width);

the NSLog prints out 768. scrolling is enabled in the scrollview in interface builder but I cannot scroll the scrollview? What could the problem be?

Upvotes: 1

Views: 635

Answers (3)

jimbob
jimbob

Reputation: 3298

I resolved the issue. It was an autolayout tick box that needed unticking in the view.

Upvotes: 1

Puneet Sharma
Puneet Sharma

Reputation: 9484

This may help: add buttons before you provide contentSize.

// add all buttons
// create contentSizeWidth presumably by adding all buttons height
contentSizeWidth = contentSizeWidth + buttonHeight;// repeat this for every button  
 [_scrollViewOutlet addSubview:button];

// create newSize
newSize.width = contentSizeWidth+400;

// set content size
  [_scrollViewOutlet setContentSize:newSize];

Upvotes: 1

emenegro
emenegro

Reputation: 6971

Mayble the proble is that the width of the frame is equal to the width of the contentSize.

Upvotes: 0

Related Questions