0
- (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 中,知道为什么吗?

4

2 回答 2

1

您的 UIButton 属于 UIButtonTypeCustom。所以你应该设置背景颜色或图像来查看按钮。

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

或者

button.backgroundColor = [UIColor redColor]

尝试这个。

于 2011-06-27T08:08:26.493 回答
0

添加按钮后,您需要设置 scrollVew 的内容大小。

于 2011-06-27T07:57:19.870 回答