How to create a UIScrollView Programmatically?

后端 未结 7 1075
后悔当初
后悔当初 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条回答
  •  -上瘾入骨i
    2020-12-01 00:15

    Simple Method: You can create multiple times if you need more

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        int x = 0;
        int y = 10;
        for(int i=0; i<5; i++)
        {
            UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 50, 50)];
            scrollview.showsVerticalScrollIndicator=YES;
            scrollview.scrollEnabled=YES;
            scrollview.userInteractionEnabled=YES;
            scrollview.backgroundColor = [UIColor greenColor];
            [self.view addSubview:scrollview];
            //scrollview.contentSize = CGSizeMake(50,50);
            x=x+55;
    
            //[self myscrollView];
        }
    }
    

提交回复
热议问题