ios 如何用drawrect方法在图像上画一条线

发布于 2024-10-19 16:02:21 字数 458 浏览 2 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘味果▽酱 2024-10-26 16:02:21

在drawRect方法中绘制图像,然后绘制线条。

[img drawAtPoint:your_point];

// Code to draw the line

Draw your image in the drawRect method, then draw the line.

[img drawAtPoint:your_point];

// Code to draw the line
俯瞰星空 2024-10-26 16:02:21

我知道已经晚了,但仍然对某人有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文