美文网首页iOS Developer
scrollView的其他属性

scrollView的其他属性

作者: 挖掘机 | 来源:发表于2016-02-16 19:54 被阅读106次

scrollView的其他属性



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//1
    UIScrollView *scrollView=[[UIScrollView alloc]init];
    scrollView.frame=CGRectMake(30, 50, 250, 250);
    
    scrollView.backgroundColor=[UIColor redColor];
    [self.view addSubview:scrollView];
//2
    for (int i=0; i<50; i++) {
        
        int row=i/3;
        int col=i%3;
        CGFloat x=col*(50+30);
        CGFloat y=row*(50+30);
        [self addGridWithX:x y:y Scroll:scrollView];
    }
    
    UIView *lastView=[scrollView.subviews lastObject];
    //CGFloat contH=lastView.frame.origin.y+lastView.frame.size.height;
  CGFloat contentH = CGRectGetMaxY(lastView.frame);
    scrollView.contentSize=CGSizeMake(0, contentH);
    
    
}
- (void)addGridWithX:(CGFloat)x y:(CGFloat)y Scroll:(UIScrollView*)scrollView
{
    UIView *grid=[[UIView alloc]init];
    grid.frame=CGRectMake(x, x, 50, 50);
    grid.backgroundColor=[UIColor blueColor];
    [scrollView addSubview:grid];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

相关文章

网友评论

    本文标题:scrollView的其他属性

    本文链接:https://www.haomeiwen.com/subject/mlapkttx.html