How to make a drawing program [closed]

2019-04-17 18:14发布

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

2条回答
看我几分像从前
2楼-- · 2019-04-17 18:29

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

查看更多
登录 后发表回答