the scrollview is not scrolling at xib file

帅比萌擦擦* 提交于 2019-12-20 02:23:44

问题


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

my code is as follow

- (void)viewDidLoad
{
    [super viewDidLoad];

    [scrollview setContentSize:CGSizeMake(1500,50)];

    [scrollview setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:scrollview];
}

回答1:


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).

Or if you want to create scrollView manually, remove from xib and use this:

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];


来源:https://stackoverflow.com/questions/17233039/the-scrollview-is-not-scrolling-at-xib-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!