【问题标题】:How to draw 1px line using BezierPath如何使用 BezierPath 绘制 1px 线
【发布时间】:2014-09-04 15:49:18
【问题描述】:

我有以下代码来绘制水平线:

UIBezierPath *topLine = [UIBezierPath bezierPath];
    [topLine moveToPoint:CGPointMake(0, topMargin + lineHeight * 2.0f)];
    [[self getTopSeparatorLineColor] setStroke];
    topLine.lineWidth = 1.0f;
    [topLine addLineToPoint:CGPointMake(rect.size.width, topMargin + lineHeight * 2.0f)];
    [topLine stroke];

它可以工作,但线路是“胖”的。我想像 UITableView 分隔符一样画线..

UIBezierPath 可以吗?

【问题讨论】:

  • 也许是0.5lineWidth1.0f 是(在视网膜设备上)两个像素宽。
  • 没什么区别
  • 应该有一些的不同。哈哈。 0.25f?
  • 0.25f 看起来更好,但我想知道如何在不猜测数字的情况下正确地做到这一点..
  • 我想如果我必须使用“魔术”数字 - 我需要知道如何确定这个数字是什么。也许使用某种 API 来获得转化?

标签: ios objective-c drawing uibezierpath


【解决方案1】:

正如 Apple UIBezierPath 类参考所说:

@property(nonatomic) CGFloat lineWidth

线宽定义了接收器的描边路径的粗细。一种 width of 0 被解释为可以在上面渲染的最细的线 特定的设备。

所以简单地做,你总是会得到 1px 的宽度:

topLine.lineWidth = 0.0f;

【讨论】:

  • 不得不把答案拿走。刚试过这个 - 根本没有画线。不在模拟器中,不在真实设备上
  • 当然。我昨天没有机会自己尝试,但我记得它在过去有效......Apple官方参考现在是?
  • 好像是这样。或者我的眼睛在说谎,他们看不到线:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-22
  • 2012-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多