Drawing 13- diary iOS Review [2020]

preamble

Drawing knowledge of the major record ios, drawing a lot of trouble, I almost do not have access to

text

Jump supplement Modal way
Modal is a jump from the bottom up, push to jump right to left
using Modal on the business logic is unrelated to the type of filling.
[Self persentViewController: UIView Animated: YES callback] // Jump
[self dismissViewControllerAnimated: YES callback] // completed
if the main to: sb line mode is set to the inside.

Draw

quartz2d is a two-dimensional drawing engine, and the iOS MacOSX, pure C language,
which is included in the frame CoreGraphics
it can draw graphics / line / triangle / rectangle / circle / arc
to draw text / drawing / image generating / reading / generating PDF
crop a picture / custom UI controls

1. Obtain graphics context objects (corresponding to writing paper)
graphics context Type: CGContextRef
2. Add the path (the path corresponding to the pen line) to a graphics context object
3. Rendering (to draw a good scratch paper, the writing paper according to target flower)


In UIview inside - (void) drawRect the drawing, which is a function of rewriting former rendering
1. obtain a context (writing paper)
CGContextRef UIGraphicsGetCurrentContext CTX = ();
2. Add stitching path simultaneously added to the context
CGContextMoveToPoints (context, the starting point x, the starting point Y);
CGContextAddLineToPoint (context, the end of x, Y end);
3. rendering
CGContextStrokePath (context);

C language, one kind of manner:
CGContextRef CGGraphicsGetCurrentContext CTX = ();
CGContextMoveToPoints ();
CGContextADdLineToPoints ();
GGContextStrokePath ();
C-way two kinds:
CGContextRef CGGraphicsGetCurrentContext CTX = ();
CGMutablePathRef CGPathCreateMutable path = (); // get variable path memory objects
CGPathMoveToPoints (path, rotational translation, the starting point x, starting y) // object is added to the variable path memory
CGPathAddLineToPoint (path, rotational translation, end point x, end y); // add paths to the variable path
CGContextaddPath (ctx, path); // add stresses array variable to the context object path
CGContetStrokePath (); // render context
C + OC embodiment three kinds of language:
CGContextRef CGGraphicsGetCurrentContext CTX = ()
UIBezierPath path * = [UIBezierPath the alloc] init]; // oc path object
[moveToPoint path: CGPointsMake (50,50);]
[path addLineToPoint: CGPointsMake (10,10);]
CGContextaddPath (ctx, path.CGPath); // oc of the path of conversion c path
CGContextStrokePath (CTX);
C + -OC language way four kinds:
CGContextRef CGGraphicsGetCurrentContext CTX = ();
CGMutablePathRef CGPathCreateMutable path = ();
CGPathMoveToPoints ( path, XXX, XXX, XXX);
CGPathAddLineToPoints (path, XXX, XXX, XXX);
// converts the path c into the path continues to paint oc
UIBezierPath path1 * = [UIBezierPath bezierPathWithCGPath: path]
[path1 addLineToPoints: CGPointsMake ( 150,50)];
CGCOntextAddPath (CTX, path1.CGPath);
CGContextStrokePath (CTX);
-OC five kinds of language mode:
UIBezierPath path * = [UIBezierPath bezierPath] // Create a path object
[path moveToPoints: CGPointsMake (50,50) ];
[addLineToPoints path: CGPointsMake (100,100)];
[Stroke path];
OC although not get the context, in fact, we have a good package inside

drawRect

1. Why the code to be written in drawRect
// written which can ensure you obtain the graphics context object
what 2.rect parameter is
// the current view of bounds
3.drawrect when to call
// when the view is first displayed calls
// when the view is redrawn calls
4. how to return
setNeedDisplay method // call view object
// call setNeedsDisplayInRect rect view of the object: to redraw the region
5. Why can not manually call drawRect
// unable to take correct the graphics context


Painting rectangular
directly obtained by the method of the object class, can then rendering
[UIBezierPath bezierPathWithRect: CGRectMake (100,100,100,100)];
[Stroke path]
or: CGContextAddRect ();
rounded rectangle
[UIbezierPath bezierPathWithRoundedRect: Rect cornerRadius: 10 ] stroke
ellipse
[UIbezierPath bezierPathWithOvalInRect : CGRectmake (0,0,200,100)]
, or: CGContextAddEllipseInRect ();
round
[UIbezierPath bezierPathWithArcCenter: center, radius, starting position, ending position, whether clockwise]
or: CGContextAddArc ();
provided linewidth
[path setLineWidth: width]
CGContextSetLineWidth (context, width);
connection pattern
[path setLineJoinStyle: enumeration style]
CGContextSetLineJoin (context, style enumeration); // KCGLineJoinRound / Bevel / Miter
head and tail pattern
[path setLineCapStyle: enumeration style]
CGContetSetLineCap (context, style enumeration); // KCGLineCapSquare
set color
[UIColor blueColor] setStroke];
CGContextSetRGBStrokeColor (context, R, G, B, alpha );


Additional attributes
CGContextClosePath (ctx) // C closed path
[path closePath] // OC closed path
CGContextStrokePath (ctx); // C is stroked rendering
[path stroke]; // OC is stroked rendering
CGContextFillPath (ctx); / / C filled rendering
[path fill]; // OC rendering stroked
CGContextDrawPath (ctx, kCGPathFillStroke); // stroke is also filled
// OC stroke and fill two methods also perform
[UIColor redColor] setFill] ; // set the fill color oc
[UIColor redColor] setStroke]; // set the stroke color oc


EOfill rule
CGContextDrawPath (ctx, kCGPathEOFill); // c
path.usesEvenOddFillRule = YES // OC
as the first cover when // rendering, not filled, or again, filled

progress bar

UISlider components

Published 15 original articles · won praise 0 · Views 2556

Guess you like

Origin blog.csdn.net/u014270781/article/details/105348517