Lob*_*ter 1 iphone objective-c uiscrollview addsubview ios
我是IOS开发的新手,但我遇到了UIScrollView的问题.首先,我在故事板中创建了Scroll View并添加了
@property (retain, nonatomic) IBOutlet UIScrollView *mainScroll;
Run Code Online (Sandbox Code Playgroud)
在视图控制器处理程序
在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];
}
Run Code Online (Sandbox Code Playgroud)
但模拟器中没有任何内容.但是,如果我在IB的故事板上添加按钮,则会出现按钮,我可以滚动视图.
对不起我的语言
试试这个代码
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.mainScroll addSubview:button];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11675 次 |
| 最近记录: |