I'm not expecting a very detailed answer here but just to be pointed in the right direction.
Let's say i wanted to make a drawing program like microsoft paint or the app draw something, how can i do this?
Do I basicly set colors on pixels and nearby pixels (for thickness) when I hover and click with the mouse?
I'm planning to make an app that requires the users to draw stuff in a simple manner, so any suggestions would be much appriciated :)
Best of regards,
Alexander
try this demo for your application
http://code4app.net/ios/Paint-Pad/4fcf74876803faec66000000
https://www.cocoacontrols.com/controls/smooth-line-view
https://www.cocoacontrols.com/controls/acedrawingview
https://www.cocoacontrols.com/controls/mgdrawingslate
it may help you.
UIBezierPath
is the good option for drawing the lines on your UIView
.For Drawing you need a custom View You can't draw on a UIViewController.
And use touch delegate methods for drawing lines.
declare an UIBezierPath *bezierPath;
in .h file
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
bezierPath=[[UIBezierPath alloc]init];
bezierPath.lineWidth = 5.0;
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[bezierPath moveToPoint:[mytouch locationInView:self]];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[bezierPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
setNeedsDisplay
will call your drawRect:
method.
- (void)drawRect:(CGRect)rect
{
[bezierPath stroke];
}
And you can change Storke color using setStroke:
property.For complete idea gone through UIBezierPath class reference.
Hope this help's you