Putting images on the screen is easy with
UIImage * myImage = [UIImage imageNamed: @"justAnImage.jpg"];
UIImageView* myImageView = [[UIImageView alloc] initWithImage: myImage];
Drawing lines from code is a bit different. Although it is a bit like JAVA.
When creating an UIImageView you get a method for free:
- (void)drawRect:(CGRect)rect
and this method draws the contents the view.
You draw in a CGContext, we have already seen CGPoint, CGPointMake etc.
(Strange is the function format: suddenly “normal”: CGPointMake ( xFloat, yFloat); —no “:” to be seen….)
The drawing is updated by:
[self setNeedsDisplay];
in the code, after you either erase or add drawing shapes.
This is for removing what was drawn:
-(void) removeLines {
CGRect elementSymbolRectangle = CGRectMake(0,0,320,480);
CGContextClearRect ( context, elementSymbolRectangle );
[self setNeedsDisplay];
}
To draw lines, first set some parameters like linewidth and color: (All CG functions)
CGContextSetRGBStrokeColor (context, .9, .9, .5, .9);
CGContextSetLineWidth(context, 2.0);
Then make an CGPointArray:
CGPoint lineArray[2];
And put your two CGPoints in the array:
lineArray[0] = point1;
lineArray[1] = point2;
Then to draw you need:
CGContextAddLines ( context, lineArray, 2 );
CGContextStrokePath(context);
A bit of a problem is this context
It has to be configured at the right moment in the drawRect, and it has to be a property of the UIView.
Better see this in action:
Example of a dodecahderon and a cube which can be rotated using touch.
I added the circles to avoid the double possibility of rotating, due to the absence of any form of perspective.
Of course in OpenGL this is all much simpler. And more complex.
