我在中添加 (400+) UIButton
s UIScrollview
,当我滚动时simulator
它运行良好,但在 iPad 中滚动缓慢。
这就是我正在做的事情。
- (void)viewDidLoad { [scrollView setContentSize:CGSizeMake(180 * 24 , 22 * 40 + 200)]; for (int e=0; e<12; e++) { for(int i=0;i<24;i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.titleLabel.font = [UIFont systemFontOfSize:12.0f]; [btn setBackgroundColor:[UIColor colorWithRed:248.0/255.0 green:248.0/255.0 blue:248.0/255.0 alpha:1]]; CALayer *layer = btn.layer; layer.cornerRadius = 5.f; layer.masksToBounds = YES; layer.borderWidth = 1.f; layer.borderColor = [[UIColor colorWithRed:190.0/255.0 green:190.0/255.0 blue:190.0/255.0 alpha:1] CGColor]; CGRect rect = btn.frame; rect.size.height = 40; rect.size.width = 50; rect.origin.x = 100 * i; rect.origin.y = 40 * e; btn.frame = rect; CAGradientLayer *shineLayer = [CAGradientLayer layer]; shineLayer.frame = layer.bounds; shineLayer.colors = [NSArray arrayWithObjects: (id)[UIColor colorWithWhite:0.9f alpha:0.5f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:0.7f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:1.f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:1.f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:1.f].CGColor,nil]; [layer addSublayer:shineLayer]; UILabel *lblDes = [[UILabel alloc] initWithFrame:CGRectMake(0,0,50,40)]; lblDes.backgroundColor = [UIColor clearColor]; lblDes.numberOfLines = 3; lblDes.textColor = [UIColor colorWithRed:4.0/255.0 green:106.0/255.0 blue:200.0/255.0 alpha:1]; lblDes.textAlignment = UITextAlignmentCenter; lblDes.text = @"adf"; lblDes.tag = -1; lblDes.font = [UIFont systemFontOfSize:11.f]; [btn addSubview:lblDes]; [scrollView addSubview:btn]; } } [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. }