0
我已经制作了我自己的UIScrollView
。带UIButton的UIScrollView:滚动后只出现按钮
在- (void)drawRect:(CGRect)rect
,我画我的按钮,这样的:
- (void) createView {
CGFloat currentY = 0;
CGFloat currentX = 0;
CGFloat currentH = 0;
for (int i = 0; i < [images count]; i++) {
UIImage *img = [images objectAtIndex:i];
CGSize cropParam = [[finalCrops objectAtIndex:i] CGSizeValue];
CGSize imgSize = [[finalSizes objectAtIndex:i] CGSizeValue];
UIImage *newImg = nil;
if (imgSize.width > 0) {
newImg = [img resize:imgSize];
}
if (cropParam.width > 0) {
newImg = [newImg crop:CGRectMake(0, 0, cropParam.width, cropParam.height)];
}
// Create a button for the image
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(currentX + margin,
currentY + margin,
newImg.size.width,
newImg.size.height)];
[button setImage:newImg forState:UIControlStateNormal];
[self addSubview:button];
currentX += 2 * margin + newImg.size.width;
if (currentX > viewWidth) {
currentX = 0;
currentY += 2 * margin + newImg.size.height;
currentH = newImg.size.height;
}
}
self.contentSize = CGSizeMake(viewWidth, currentY);
}
的问题是,认为出现的时候,它是黑色的。该按钮仅在滚动视图时出现。
我错过了什么?
我试过把setneedsdisplay放在drawrect的结尾或在createView中,但是不会改变任何东西。 – 2012-03-23 17:07:56