Draw an annotation drawing in objective c iOS || Hand drawing in iOS
Solution:
You had your own first point and last point.
Follow the below steps to draw an annotation icon inside the rectaView.
We had using the arc method to draw the annotation inside the rectView.
You had your own first point and last point.
Follow the below steps to draw an annotation icon inside the rectaView.
We had using the arc method to draw the annotation inside the rectView.
CGContextRef context = UIGraphicsGetCurrentContext();
// set the properties
CGContextSetAlpha(context, 1.0);
CGFloat x1 = MIN(self.firstPoint.x, self.endPoint.x);
CGFloat y1 = MIN(self.firstPoint.y, self.endPoint.y);
CGFloat x2 = MAX(self.firstPoint.x, self.endPoint.x);
CGFloat y2 = MAX(self.firstPoint.y, self.endPoint.y);
// draw the rectangle
CGRect rectToFill = CGRectMake(x1, y1, x2, y2);
CGFloat rectFillX = fabs(rectToFill.origin.x)-15;
CGFloat rectFillY = fabs(rectToFill.origin.y)-15;
CGFloat rectFillWidth = fabs(rectToFill.size.width)-15 ;
CGFloat rectFillHeight = fabs(rectToFill.size.height)-1 5;
rectToFill.origin.x = rectFillX;
rectToFill.origin.y = rectFillY;
rectToFill.size.width = rectFillWidth;
rectToFill.size.height = rectFillHeight;
float percentage10 = rectFillHeight * (10.0f / 100.0f);
float percentage20 = rectFillHeight * (20.0f / 100.0f);
float percentageW20 = rectFillWidth * (20.0f / 100.0f);
float percentage30 = rectFillHeight * (30.0f / 100.0f);
float percentageW30 = rectFillWidth * (30.0f / 100.0f);
CGContextMoveToPoint(context, rectFillX, rectFillY+rectFillHeight);
CGContextAddLineToPoint( context, rectFillX+percentageW20, rectFillY+rectFillHeight- percentage30);
CGRect arcRect = CGRectMake(rectFillX, rectFillY, rectFillX+rectFillWidth, rectFillY+rectFillHeight- percentage20);
float c1 = ((rectFillY+rectFillHeight- percentage20)+((arcRect.origin .y+arcRect.origin.y+arcRect.si ze.height)/2))/2;
CGContextAddCurveToPoint( context, rectFillX+ percentageW20, rectFillY+rectFillHeight- percentage30, arcRect.origin.x, c1, arcRect.origin.x, (arcRect.origin.y+arcRect.orig in.y+arcRect.size.height)/2);
CGContextAddCurveToPoint( context, arcRect.origin.x, (arcRect.origin.y+arcRect.orig in.y+arcRect.size.height)/2, arcRect.origin.x, arcRect.origin.y, (arcRect.origin.x+arcRect.orig in.x+arcRect.size.width)/2, arcRect.origin.y);
CGContextAddCurveToPoint( context, (arcRect.origin.x+arcRect.orig in.x+arcRect.size.width)/2, arcRect.origin.y, arcRect.origin.x+arcRect.size. width, arcRect.origin.y, arcRect.origin.x+arcRect.size. width, (arcRect.origin.y+arcRect.size .height+arcRect.origin.y)/2);
CGContextAddCurveToPoint( context, arcRect.origin.x+arcRect.size. width, (arcRect.origin.y+arcRect.orig in.y+arcRect.size.height)/2, rectFillX+rectFillWidth, rectFillY+rectFillHeight- percentage10, arcRect.origin.x+ percentageW30, arcRect.origin.y+arcRect.size. height-percentage20);
CGContextAddLineToPoint( context, rectFillX, rectFillY+rectFillHeight);
CGContextStrokePath(ctx);
Comments
Post a Comment