0

I have two UIViews in scrollview where both the views has subviews with Autolayout OFF under it

- MainView
   - ScrollView 
      - UIView
         -UIButtons 
         -UIButtons
      - UIView
         - Navigation Bar
         - UIImageView 
         - UIImageView 

The first UIView under ScrollView has UIButtons which is going to be dynamic depending upon that I want to set the height and position of the second view`.

say if there are three buttons then the next UIView should go down w.r.t to the height of the first UIView.

While trying to achieve this I am not able to set the height of UIView at runtime?

EDIT: Here's what I am doing I am changing the content size of scrollview:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

//    CGRect frame = self.myGamesSection.frame;
//    frame.size.height = 100.0f;
//    self.myGamesSection.frame = frame;
}


-(void) viewDidAppear:(BOOL)animated {
    CGSize rSize = CGSizeMake(320.0f,1200.0f);
    self.scrollView.contentSize = rSize;     
}

-(void) viewWillAppear:(BOOL)animated {     
    CGSize rSizeMyGames = CGSizeMake(320.0f,100.0f);
    self.myGamesSection.frame = CGRectMake(0,47,320, 100);
}
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
user1169079
  • 3,053
  • 5
  • 42
  • 71

3 Answers3

0

Add a UIScrollView on UIView, then add your buttons. Don't for got to change the contentSize of the scrollView based on your button size.

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
0

Last time I faced similar problem, when content size of scroll view should vary at run time, I just switched to UITableView instead of UIScrollView, there you can always specify cell height in delegate's method heightForRowAtIndexPath: and send reloadData to tableView each time it should changed. Perhaps it's not the best solution, but it works.

user2260054
  • 522
  • 1
  • 3
  • 11
  • When I was starting to work on this I was not sure what I should go for that's why had asked this ..http://stackoverflow.com/questions/23210814/uidesign-advice-for-the-application but then using two tableview in one view controller I think design will not look like one page design – user1169079 Apr 23 '14 at 09:46
  • Well, I don't see any reasons to use two tableViews here. Or your two sections should be scrollable independently from each other? You can use one table with two rows and one more: you can specify any custom view as a contentView of a cell when configuring it in cellForRowAtIndexPath dataSource method. – user2260054 Apr 23 '14 at 09:54
  • By the way, UITableView inherits from UIScrollView so you don't need to put it above UIScrollView to make it scrollable and you can use just mainView-> tableView. – user2260054 Apr 23 '14 at 09:56
  • No two sections should not be scrollable independently it should be one page ... So can I achieve that two big UImageViews in a cell with that layout ?? any link where I can just see example of this ... – user1169079 Apr 23 '14 at 09:58
  • Great, you can customize cell just as you want https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html Check Listing 5-7 in particular. – user2260054 Apr 23 '14 at 10:02
0

You can use this type of logic...

     //Keep a variable which hold your yOffsetPositon and loop to add buttons. After that set the height of view.
        int yPos = 0;
        UIView *firstView = [[UIView alloc] initWithFrame:frame];
        for (int =i =0; i<10; i++){
         UIButton *b = [[UIButton alloc] initWithFrame:CGRectMake(0,yPos,30,30)];
        yPos+=30;
        //if you want spacing
        //yPos+=10;
        }
//reset height of firstView
        fistView.frame = CGRectMake(frame.origin.x,frame.origin.y,yPos,frame.size.width);
       //Set height of second view 
        UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0,firstView.frame.size.height+10,HEIGHT,Width)];
Adnan Aftab
  • 14,377
  • 4
  • 45
  • 54