Wednesday, June 5, 2013

UIBezierPath lineJoinStyle example in Objective C (iOS).


UIBezierPath lineJoinStyle

The shape of the joints between connected segments of a stroked path.

@property(nonatomic) CGLineJoin lineJoinStyle

Discussion of [UIBezierPath lineJoinStyle]
The default line join style is kCGLineJoinMiter.

UIBezierPath lineJoinStyle example.
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth=5;
    myPath.miterLimit=-10;
    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 lineJoinStyle].
myPath=[[UIBezierPath alloc]init];
myPath.lineCapStyle=kCGLineCapSquare;
myPath.lineJoinStyle = kCGLineJoinBevel;
myPath.lineWidth=5;
myPath.flatness = 0.4;

UIBezierPath lineJoinStyle example.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(isFirstTapp)
    {
        isFirstTapp=NO;
        [self.spooleteView removeHandView];
    }
    isdraw=YES;
    mouseSwapped=NO;
    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];


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

    self.selectedColor = [brushColor objectAtIndex:colorTag];

    if(isErase)
    {
        myPath.lineWidth=30.0;
        self.selectedColor = [UIColor whiteColor];

    }
    else
    {
        if([mode isEqualToString:@"morsecode"])
            myPath.lineWidth=10.0;
        else
            myPath.lineWidth=5.0;
    }

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

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

End of UIBezierPath lineJoinStyle example article.