我在我的应用程序中使用 UIScrollView
,我的要求是我必须向 UIScrollView
添加背景颜色,但是当用户拖动到最顶端或最顶端时bottom 除了内容之外的区域/在 ScrollView 中显示的内容应该用不同的颜色显示,就像在 UIWebView
中一样。在 WebView 中,如果我们在顶部向下拖动或在底部向上拖动,它将显示默认背景图像/灰色, WebView 内容背景颜色为 diff(默认白色)。任何人都可以帮助我实现这一目标。
谢谢。
最佳答案
诀窍是向位于内容上方和下方的 ScrollView 添加 subview 。这样,它们仅在内容被向上或向下拖动时出现。
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, -200, scroll.bounds.size.width, 200)];
[topView setBackgroundColor:[UIColor darkGrayColor]];
[scroll addSubview:topView];
[topView release];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, scroll.bounds.size.height, scroll.bounds.size.width, 200)];
[bottomView setBackgroundColor:[UIColor darkGrayColor]];
[scroll addSubview:bottomView];
[bottomView release];
关于iphone - 如何为 UIScrollView 中的内容区域设置背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13699726/