在 uiviewcontroller 的视图中绘制水平线和垂直线
我有一个带有一些图像的 UIViewController 。我需要在图像之间绘制一些水平线和垂直线。实际上它就像一个层次结构视图。添加带有背景颜色的子视图是最好的方法吗?
I have a UIViewController with some images. I need to draw some horizontal and vertical lines in between images. Actually its like a hierarchy view. Is adding subviews with background color the best way to go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用了 Magic Bullet Dave 发布的第三个选项,效果很好。代码如下:
如果你想制作一条垂直线,你只需使用宽度 1,然后使用所需的高度。
I used the 3rd option posted by Magic Bullet Dave and it is working great. Here's the code:
If you want to make a vertical line you'd simply use a width of 1 and then the height desired.
您有 3 种基本方法:
3 可能是最容易实现的,但不是最优雅的,1 就内存而言是最强大的,因为您还可以使用 drawInRect 将图像绘制到相同的图形中 语境。这会将视图层次结构折叠为单个视图。
You have 3 basic approaches:
3 is probably the easiest to implement, but not the most elegant, 1 is the most robust in terms of memory as you can also use drawInRect to draw your images into the same graphics context. This collapses the view hierarchy into a single view.
您可以使用上面回答的图层来完成此操作,或者只是因为您只想要线条,所以使用
UIViews
就像这样
希望有帮助
You can do it using layers as answered above or simply since you want just lines,use
UIViews
Just like this
Hope that helps