0
自分でUIScrollView
を作成しました。 - (void)drawRect:(CGRect)rect
でUICuttonを使用したUIScrollView:スクロール後にボタンが表示される
、私はそのように私のボタンを描画した:
- (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に置いてみましたが、何も変更しませんでした。 –