【发布时间】:2013-09-24 07:59:03
【问题描述】:
我是 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 的情节提要上添加一个按钮,则会出现该按钮并且我可以滚动视图。
如何在代码中添加按钮?
【问题讨论】:
-
您在使用 ARC 吗?如果你不是,你应该是。
-
确保在按钮框架上。为什么你设置绑定除了 .0f 和 0.f 是按钮的 x 和 y 线。请检查框架大小。
标签: iphone ios objective-c uiscrollview addsubview