ios 如何用drawrect方法在图像上画一条线
我有一个名为 imgView 的 UIImageView,当我在视图的 drawrect
方法中画线时添加它
[self.view addSubview:imgView];
,该线显示在 imgView 下方,但我希望它显示在 imgView 上。 ps:我也尝试过
[self.view insertSubview:imgView atIndex:0];
隐藏 imgView,即我可以在视图上看到它
[self.view addSubview:imgView];
,但这
[self.view sendSubviewToBack:imgView];
也不起作用。
可能出什么问题了?
I have a UIImageView called imgView which was added by
[self.view addSubview:imgView];
when I draw line in view's drawrect
method, the line shows below imgView, but i want it shows on imgView. ps: i also tried
[self.view insertSubview:imgView atIndex:0];
which hides the imgView i.e I could see it on the view
[self.view addSubview:imgView];
and
[self.view sendSubviewToBack:imgView];
that also didn't work.
What could be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在drawRect方法中绘制图像,然后绘制线条。
Draw your image in the drawRect method, then draw the line.
我知道已经晚了,但仍然对某人有用。
line 位于图像下方的原因 - 是因为您在 drawRect 中执行的所有操作都将位于每个子视图下方。因此,如果您想要在图像顶部画一条线,则需要向 imageview 添加一个 UIView 子视图类,其中您有相应的带有线条绘制的drawrect。
I know it's late, but still, could be usefull to someone.
The reason why line is under image - is because everything you do in drawRect, will be below every subview. So if you would want a line on top of image, you would need to add to imageview an UIView subview class, in which You have corresponding drawrect with line drawing.