iphone - 在两个 ScrollView 之间添加垂直线(边框)

标签 iphone ipad ios

我有两个 UIScrollView 实例,我想在它们之间画一条垂直线(不是 100% 高度,更像是 80%)。我怎样才能做到这一点?

最佳答案

使用核心图形。将两个 UIScrollView 嵌套在另一个 View 中,并覆盖父级的 drawRect 方法。参见 Apple 的 UIView documentation对于 drawRect 更多细节和 Core Graphics Context Reference有关绘图的更多信息。

- (void) drawRect: (CGRect) rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    // Draw divider
    UIGraphicsPushContext(context);
        // Fill the background, this must happen if the view is not opaque.
            if (self.opaque)
            {
            [[UIColor whiteColor ] set];
            CGContextFillRect(context, rect);
            }

        [[UIColor grayColor] set];

        CGContextSetLineWidth(context, 1);

        CGContextBeginPath(context);
        CGContextMoveToPoint(context, rect.size.width * 0.5, 0.1 * rect.size.height);
        CGContextAddLineToPoint(context, rect.size.width * 0.5, 0.9 * rect.size.height);
        CGContextStrokePath(context);
    UIGraphicsPopContext(); 
}

编辑

为了解决我的疏忽,据我所知,没有一种简单的方法可以在 subview 上绘制。

可以使用与上面相同的基本 View 层次结构来模拟此行为。子类 UIView 以创建不接受任何触摸事件的完全透明 View 。将绘图代码(我在上面的代码中添加了不透明度的条件)放在自定义 View 中,然后在 View 层次结构的前面插入自定义 View 的实例。

关于iphone - 在两个 ScrollView 之间添加垂直线(边框),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4686344/

相关文章:

ios - NSMutableDictionary 的错误设置值

iphone - 如何在iOS中从 View 顶部添加带有拖动动画的 subview ?

iPhone 应用程序产品名称

iphone - 如何在 iPhone 上的 OpenGL ES 中设置/获取纹理上的像素?

iphone - 我可以知道ipad是否重新启动吗?

javascript - window.location.href 在 iPad 上不起作用

iphone - iPad 播放 Youtube 链接

ios - UIScrollView 高度和宽度

iphone - 从 iPhone 应用程序发出 GET 和 POST 请求 - 需要说明

ios - 本地化 Storyboard : How to add new content?