How to create a UIScrollView Programmatically?

后端 未结 7 1077
后悔当初
后悔当初 2020-11-30 23:38

Alright, so the key here is I\'m not using IB at all, because the View I\'m working with is created programmatically. The UIView covers the lower half the scre

7条回答
  •  独厮守ぢ
    2020-12-01 00:16

    This may be helpful to you for creating the uiscrollview programmatically
    http://unconditionalloop.blogspot.com/2011/04/uiscrollview-programmatically.html

      UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];   
         NSInteger viewcount= 4;  
         for(int i = 0; i< viewcount; i++) { 
    
            CGFloat y = i * self.view.frame.size.height;  
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, self .view.frame.size.height)];       
            view.backgroundColor = [UIColor greenColor];  
            [scrollview addSubview:view];  
            [view release];  
         }    
      scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *viewcount);   
      [self.view addSubview:scrollview];
    

提交回复
热议问题