問題描述
我是 iphone 開發新手.我在我的應用程序中添加了滾動視圖,并在滾動視圖中以圖形方式添加了 10 個按鈕.但是當我運行滾動視圖時沒有滾動
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
我的代碼如下
- (void)viewDidLoad
{
[super viewDidLoad];
[scrollview setContentSize:CGSizeMake(1500,50)];
[scrollview setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:scrollview];
}
推薦答案
看來你是在xib中使用scrollview.因此,您需要從代碼中刪除 [self.view addSubview:scrollview];
并且您可以直接在 xib 中設置該滾動視圖的屬性,除了 setContentSize(您需要在 .m 文件中設置).
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).
或者如果你想手動創建scrollView,從xib中移除并使用這個:
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];
這篇關于滾動視圖不在 xib 文件中滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!