Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UITableViewCell中绘制实线_Iphone - Fatal编程技术网

Iphone 在UITableViewCell中绘制实线

Iphone 在UITableViewCell中绘制实线,iphone,Iphone,我对图形或绘画一无所知,所以我想这就是为什么我不知道该找什么来解决这个问题 这是我在UITableViewCell的drawRect中得到的 - (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(ctx, 0.0, 0.0, 0.0, 1.0); CGCon

我对图形或绘画一无所知,所以我想这就是为什么我不知道该找什么来解决这个问题

这是我在UITableViewCell的drawRect中得到的

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(ctx, 0.0, 0.0, 0.0, 1.0);
    CGContextSetLineWidth(ctx, 0.25);

    for (int i = 0; i < [columns count]; i++) {
        CGFloat f = [((NSNumber*) [columns objectAtIndex:i]) floatValue];
        CGContextMoveToPoint(ctx, f, 0);
        CGContextAddLineToPoint(ctx, f, self.bounds.size.height);
    }
    CGContextStrokePath(ctx);
}
-(void)drawRect:(CGRect)rect{
[超级drawRect:rect];
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx,0.0,0.0,0.0,1.0);
CGContextSetLineWidth(ctx,0.25);
对于(int i=0;i<[列计数];i++){
CGFloat f=[((NSNumber*)[columns objectAtIndex:i])floatValue];
CGContextMoveToPoint(ctx,f,0);
CGContextAddLineToPoint(ctx,f,self.bounds.size.height);
}
CGContextStrokePath(ctx);
}

我认为这应该是画一条黑色的线,但这条线是灰色的,与背景中的东西混合在一起。如何绘制不受背景图像影响的实线?我已经尝试了所有混合模式的想法,可能其中一个会像混合模式none,因为我不想要任何混合,但所有绘制的线条都以某种方式与背景混合。

您可以尝试使用关闭抗锯齿。另外,0.25似乎是一条很细的线。将其设置为1.0可能会满足您的需要。

您可以尝试使用关闭抗锯齿功能。另外,0.25似乎是一条很细的线。将其设置为1.0可能会为您提供所需信息。

两个问题: *你画了一条0.25像素宽的黑线(在iPhone4上是0.5像素);抗锯齿将使其显示为半透明。尝试将线宽设置为1。 *如果f是整数,则线的中心在像素边界上对齐(您希望它在像素中心上)。尝试添加0.5f

如果想在iPhone4上使用更细的线条,请检查self.layer.scale==2,如果是,请将线条宽度设置为0.5并添加0.25f

或者,设置填充颜色并调用CGContextFillRect(),这意味着您不必担心像素中心。

两个问题:
UIView *line = [[UIView     alloc]initWithFrame:CGRectMake(100,0,1,44)];
line.backgroundColor = [UIColor     colorWithRed:244.0f/255.0f green:244.0f/255.0f     blue:244.0f/255.0f alpha:1];

[cell addSubview:line];
*你画了一条0.25像素宽的黑线(在iPhone4上是0.5像素);抗锯齿将使其显示为半透明。尝试将线宽设置为1。 *如果f是整数,则线的中心在像素边界上对齐(您希望它在像素中心上)。尝试添加0.5f

如果想在iPhone4上使用更细的线条,请检查self.layer.scale==2,如果是,请将线条宽度设置为0.5并添加0.25f

或者,设置填充颜色并调用CGContextFillRect(),这意味着您不必担心像素中心

UIView *line = [[UIView     alloc]initWithFrame:CGRectMake(100,0,1,44)];
line.backgroundColor = [UIColor     colorWithRed:244.0f/255.0f green:244.0f/255.0f     blue:244.0f/255.0f alpha:1];

[cell addSubview:line];