Wednesday, June 5, 2013

UIBezierPath lineWidth example in Objective C (iOS).

UIBezierPath lineWidth

The line width of the path.

@property(nonatomic) CGFloat lineWidth

Discussion of [UIBezierPath lineWidth]
The line width defines the thickness of the receiver's stroked path. A width of 0 is interpreted as the thinnest line that can be rendered on a particular device. The actual rendered line width may vary from the specified width by as much as 2 device pixels, depending on the position of the line with respect to the pixel grid and the current anti-aliasing settings. [UIBezierPath lineWidth] The width of the line may also be affected by scaling factors specified in the current transformation matrix of the active graphics context.

The default line width is 1.0.

UIBezierPath lineWidth example.
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    myPath=[[UIBezierPath alloc]init];
    myPath.lineCapStyle = kCGLineCapRound;
    myPath.lineJoinStyle = kCGLineJoinMiter;
    myPath.flatness = 0.0;  

    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath moveToPoint:[mytouch locationInView:self]];
    [pathArray addObject:myPath];


Example of [UIBezierPath lineWidth].
myPath=[[UIBezierPath alloc]init];
myPath.lineJoinStyle = kCGLineJoinBevel;
myPath.flatness = 0.4;

UIBezierPath lineWidth example.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
        [self.spooleteView removeHandView];
    UITouch *touch = [touches anyObject];
    lastPoint=[touch locationInView:self];

    //UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [currentPath moveToPoint:p];
    currentPath.flatness = 10.0;

    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    UIBezierPath *myPath=[[UIBezierPath alloc]init];

    [dict setObject:myPath forKey:@"Path"];
    colorTag= [[AppHelper userDefaultsForKey:@"ColorTag"]intValue];

    self.selectedColor = [brushColor objectAtIndex:colorTag];

        self.selectedColor = [UIColor whiteColor];

        if([mode isEqualToString:@"morsecode"])

    //[dict setObject:[brushColor objectAtIndex:colorTag] forKey:@"Colors"];
    [dict setObject:self.selectedColor forKey:@"Colors"];

    [myArr addObject:dict];
    currentPath.flatness = 0.1;
    currentPath.lineJoinStyle = kCGLineJoinRound;
    [myPath moveToPoint:lastPoint];
    [myPath release];
    [dict release];   

End of UIBezierPath lineWidth example article.