Draw a genuine 1-pixel line, iOS7 [duplicate]

2019-07-20 02:04发布

This question already has an answer here:

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

(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) 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.)

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) Ideally, it would work sweetly in interface builder, i.e. wysiwyg in your xib!


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

1条回答
Fickle 薄情
2楼-- · 2019-07-20 02:39

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.

查看更多
登录 后发表回答