绘制一个真正的1像素线,iOS7 [英] Draw a genuine 1-pixel line, iOS7

查看:376
本文介绍了绘制一个真正的1像素线,iOS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(A)iOS7在界面中使用正版1像素线是司空见惯的。

(A) It's commonplace that iOS7 uses genuine 1 pixel lines in interface.

(B)你可以轻松画一个 point 行(大概是每个人都知道点和像素之间的差异),在你的XIB中,通过使用1单位高的UIView,黑色背景。事实上,这是一个非常方便的事情,但它不会像1像素纯黑线那样绘制。

(B) You can easily draw a one point line (presumably everyone here knows the difference between points and pixels), in your XIBs, by using a UIView which is 1 unit high, with a black background. Indeed, this is a very handy thing, BUT it does not draw anything like a 1 pixel pure black line.

(C)当然,您可以使用精灵,一个PNG - 但那是可怜的。 (如果你不幸的话必须支持那些,那么在古老的非视网膜显示器上使它真正一致也非常困难。)

(C) You can, of course, use a sprite, a PNG - but that's pathetic. (It's also remarkably difficult to make it really consistent on the ancient non-retina displays, if you unfortunately must support those.)

是否有一种简单的添加方法,一些有点招数,添加一个真正的1像素黑线?水平还是理想垂直?

Is there a simple way to add, some sort of trick, to add a genuine 1-pixel black line? Horizontal or ideally vertical also?

(D)理想情况下,它会在界面构建器中甜蜜地工作,即你的xib中的wysiwyg!

(D) Ideally, it would work sweetly in interface builder, i.e. wysiwyg in your xib!

注意 ..对于任何想要这样做的人,我刚刚意识到基本问题是在界面构建器中,你可以热输入非整数金额。当然,在代码中你可以输入0.5(或更好,1.0 / [UIScreen mainScreen] .scale) - 这就是它!保存您输入的完整答案..

Note .. for anyone wanting to do this, I've just realised the fundamental issue is that in interface builder, you can hot enter non-integer amounts. Of course, in code you can enter 0.5 (or better, 1.0/[UIScreen mainScreen].scale)- so that's it! Full answer to save you typing..

https:// stackoverflow.com/a/22694062/294884

https://stackoverflow.com/a/22694062/294884

推荐答案

子类UIView,填写drawRect方法用你完成任务所需的任何代码。您可以将IB中的UIView子类默认为具有黑色背景,以便获得WYSIWYG的感觉,但是当它绘制时(通过代码),它可以更具体地满足您的需求。

Subclass UIView, fill in the drawRect method with whatever code you need to accomplish the task. You can default the UIView subclass in IB to have a black background so you get the WYSIWYG feel but when it draws (via code) it can be more specific to your needs.

这篇关于绘制一个真正的1像素线,iOS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆