我需要向 UIScrollview 添加多个按钮(它取决于数组计数)。现在我正在使用以下代码。此代码工作正常,但此功能需要更多时间(添加按钮的延迟)。请帮助我..
for (int i=0; i< [imageArray count]; i++) {
NSURL *url = [NSURL URLWithString:[[imgArray objectAtIndex:i]objectForKey:@"url"]];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(xp, 0, 75, 75);
[button1 setImage:img forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
button1.layer.borderColor = [UIColor whiteColor].CGColor;
button1.layer.borderWidth = 2.0;
[mScrollView addSubview:button1];
xp += button1.frame.size.width+15;
}