【问题标题】:How to draw a plain (non tranparent) line?如何绘制一条普通(非透明)线?
【发布时间】:2012-03-21 09:58:01
【问题描述】:

在“-(void)drawRect:(CGRect)rect”方法内的 UIView 中。 我想画一条普通的黑线(作为边框),但我总是得到一条半透明的线。 只有角落的四个点是完全黑色的。 这是为什么呢?

这是我的代码:

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAlpha(context,1.0);
CGContextSetRGBStrokeColor(context,0.0,0.0,0.0,1.0);
CGContextMoveToPoint(context,0.0,0.0);
CGContextAddLineToPoint(context,rect.size.width,0.0);
CGContextAddLineToPoint(context,rect.size.width,rect.size.height);
CGContextAddLineToPoint(context,0.0,rect.size.height);
CGContextClosePath(context);
CGContextStrokePath(context);
}

【问题讨论】:

    标签: ios4 uiview cgcontext


    【解决方案1】:

    如果你想给 UIView 添加边框,你也可以这样做

    yourView.layer.borderColor = [UIColor blackColor].CGColor;
    yourView.layer.borderWidth = 2.0f;
    

    别忘了导入 QuartzCore 框架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多