2012-02-22 93 views
0

我有一个UIViewController,它有一个UIImageView。我想在UIImageView上画一条线。我知道为了做到这一点,我必须重写UIView中的drawRect。有没有其他的选择?从UIViewController绘制一条线

+0

我下面回答,但你为什么不希望覆盖的drawRect? – picciano 2012-02-22 20:40:58

+0

,因为如果只有一个带有drawRect的UIImage类就会很烦人? – adit 2012-02-22 22:07:32

回答

0

重写drawRect可能是最好的解决方案,但总是有其他选择。

如果行是水平或垂直的,您可以使用所需行的框架创建UIView并设置其背景色。

您可以覆盖该行的图像,根据需要旋转/调整大小。

1

事情是这样的:

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); 
CGContextSetLineWidth(context, 1.0f); 
CGContextMoveToPoint(context, 0, 0); 
CGContextAddLineToPoint(context, view.frame.size.width, view.frame.size.height); 
CGContextStrokePath(context); 
+0

在这里查看我的图像视图? – adit 2012-02-22 21:40:41

+0

@adit,我不知道你的imageview名称是什么。这只是一个常见的例子。 – beryllium 2012-02-23 07:23:20