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
网友评论