Ios4 如何绘制一条普通(非父)线?

Ios4 如何绘制一条普通(非父)线?,ios4,uiview,cgcontext,Ios4,Uiview,Cgcontext,在-voiddrawRect:cGrect方法内部的UIView中。 我想画一条纯黑色的线作为边框,但我总是得到一条半透明的线。 只有拐角处的四个点是完全黑色的。 为什么呢 这是mycode: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetAlpha(context,1.0); CGContextSetRGBStrokeColor(context,

在-voiddrawRect:cGrect方法内部的UIView中。 我想画一条纯黑色的线作为边框,但我总是得到一条半透明的线。 只有拐角处的四个点是完全黑色的。 为什么呢

这是mycode:

- (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);
}

如果要向UIView添加边框,也可以按如下操作

yourView.layer.borderColor = [UIColor blackColor].CGColor;
yourView.layer.borderWidth = 2.0f;
别忘了导入QuartzCore框架