- (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];
}
遵循这里的方法:在 UIScrollView 中自动布局图像
但是我的 UIButton 没有出现在我的 scrollView 中,知道为什么吗?