创建网格线并允许用户打开/关闭网格线视图
我想在我的应用程序中创建网格线方法,并允许用户打开/关闭网格视图。它不需要任何类型的触摸检测或与之相关的逻辑。只是网格线供用户查看并打开/关闭它们。显而易见的解决方案是将网格图像添加到我的视图中,并在需要时使用图像视图显示它。但这是我不能接受的选择。我必须以编程方式完成它。感谢您抽出时间。我计划实施的图片 。有什么想法吗?核心显卡还是很多 uiview?
I would like to create a grid line approach in my app and allow the user to switch on/off the grid view. It doesn't need to have any sort of touch detection or a logic associated to it. Just grid lines for the user to see and turn them on/off. The obvious solution for this would be to add an image of grid to my view and display it whenever required using an imageview. But that is an option that I cannot take. I have to do it programmatically. Thanks for your time. An image of what I am planning to implement. Any ideas ? Core graphics or many uiviews ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已将其用于 Swift3
并将其背景颜色设置为
clear
。该代码也位于此处
I have used this for Swift3
And set its background colour as
clear
.The code is also present here
子类化 UIView 并在其中创建单独的 2 个循环。一种用于垂直线,一种用于水平线。
在垂直线循环中,创建 UIView 的 1px 宽和 768px 高。在水平方向上,将它们创建为 1 像素高和 1024 像素宽。
要隐藏和显示它,只需将子类视图的隐藏属性切换为 YES 或 NO 即可。
您也可以不使用子类化,只需使用标准 UIView。
Subclass a UIView and create separate 2 loops in there. One for vertical lines and one for horizontal lines.
In the vertical lines loop, create UIView’s 1px wide and 768px high. In horizontal one, create them 1px high and 1024px wide.
To hide and show it, just switch the subclassed view’s hidden property to either YES or NO.
You can possibly do without the subclassing as well, just use a standard UIView.
最终使用了这个:
Ended up using this: