I am new in iphone development.. I have added the scrollview in my app and added 10 buttons graphically inside the scrollview. but when I run the scrollview is not scrolling
我是iphone开发的新手。我在app中添加了scrollview,并在scrollview中图形化地添加了10个按钮。但是当我运行scrollview时,它并没有滚动
my code is as follow
我的代码如下
- (void)viewDidLoad
{
[super viewDidLoad];
[scrollview setContentSize:CGSizeMake(1500,50)];
[scrollview setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:scrollview];
}
2
It looks like you are taking scrollview in xib. So, you need to remove [self.view addSubview:scrollview];
from your code and you can directly set properties of that scrollview in xib except setContentSize(that you need to set in .m file).
看起来您正在使用xib中的scrollview。因此,您需要删除[self。视图addSubview scrollview):;从您的代码中,您可以在xib中直接设置该scrollview的属性,除了setContentSize(您需要在.m文件中设置)。
Or if you want to create scrollView manually, remove from xib and use this:
或者如果您想手动创建scrollView,请从xib中删除并使用以下命令:
UIScrollView * cOntent= [[UIScrollView alloc] initWithFrame:self.view.bounds];
[content setContentSize:CGSizeMake(width, height)];
//Here you can add those buttons to content view
[self.view addSubView:content];