我是 iOS 开发的新手,我对UIScrollView
. 首先,我在情节提要中创建了一个滚动视图并添加了
@property (retain, nonatomic) IBOutlet UIScrollView *mainScroll;
在视图控制器处理程序中
在该viewDidLoad
方法中,我有以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.mainScroll.contentSize = CGSizeMake(100.0,100.0); // Have to set a size here related to your content.
// You should set these.
self.mainScroll.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mainScroll.minimumZoomScale = .5; // You will have to set some values for these
self.mainScroll.maximumZoomScale = 2.0;
self.mainScroll.zoomScale = 1;
UIButton* b = [[UIButton alloc] init];
[b setBounds:CGRectMake(.0f,0.f,100.0,100.0)];
[self.mainScroll addSubview:b];
}
但是该按钮不会出现在模拟器中。但是,如果我在 IB 的情节提要上添加一个按钮,则会出现该按钮并且我可以滚动视图。
如何在代码中添加按钮?