开发者

UIButton with CGRect doesn't appear in UIScrollView

- (CGPoint)getImageOrigin:(NSInteger)imageNumber {
CGFloat leftInset = 40;
CGFloat xOffsetBetweenOrigins = 100;
CGFloat topInset = 40;
CGFloat yOffsetBetweenOrigins = 100;
int numPerRow = 3开发者_如何学C;
CGFloat x = leftInset + (xOffsetBetweenOrigins * (imageNumber % numPerRow));
CGFloat y = topInset + (yOffsetBetweenOrigins * floorf(imageNumber / numPerRow));
CGPoint imageOrigin = CGPointMake(x, y);
return imageOrigin;
}

-(void)viewDidLoad{
UIButton *zenbutton2 =[UIButton buttonWithType:UIButtonTypeCustom];
CGRect newFrame = zenbutton2.frame;
newFrame.origin = [self **getImageOrigin**:i];
zenbutton2.frame = newFrame;
[scrollView addSubview:zenbutton2];  
}

followed the method here : laying out images in UIScrollView automatically

but my UIButton doesnt appear in my scrollView , any idea why?


Your UIButton is of UIButtonTypeCustom. So you should set a background color or Image to see the button.

[button setImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];

or

button.backgroundColor = [UIColor redColor]

Try this.


You need to set scrollVew's content size after adding button's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜