- (CGPoint)getImageOrigin:(NSInteger)imageNumber {
CGFloat leftInset = 40;
CGFloat xOffsetBetweenOrigins = 100;
CGFloat topInset = 40;
CGFloat yOffsetBetweenOrigins = 100;
int numPerRow = 3;
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];
}
遵循此处的方法:laying out images in UIScrollView automatically
但是我的UIButton没有出现在我的uiscrollView中,任何想法为什么?
答案 0 :(得分:1)
您的UIButton属于UIButtonTypeCustom。因此,您应该设置背景颜色或图像以查看按钮。
[button setImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];
或
button.backgroundColor = [UIColor redColor]
试试这个。
答案 1 :(得分:0)
添加按钮后,您需要设置scrollVew的内容大小。