iphone - 如何为 UIScrollView 中的内容区域设置背景颜色?

标签 iphone ios ipad uiscrollview uiscrollviewdelegate

我在我的应用程序中使用 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/

相关文章:

ios - 如何在 ios 中重新注册推送通知

iphone - UILocalNotification和iOS 4.2

iphone - Cocos2d-iPhone : Handle Button Press and Release

iphone - 保留CGPath对象时遇到麻烦(出现警告)

ios - 如何正确拖放、旋转和缩放 UIView?

iphone - iOS : Why does Memory Monitor disagree with Allocations? 仪器

html - 在 iPad 上查看时,两个固定位置的 div 会产生边距

ios - Swift 3 - 我使用哪种像素格式类型来获得最佳的 Tessecract 文本识别?

ios - XCTAssertEqualObjects 和 NSManagedObjects

ios - 如何将 'Done' 按钮添加到 iOS 键盘 [Webview/Phonegap/Cordova]