4

I have integrated drawing a line in my application. I have not used OpenGl or any other similar framework. Now I want to give a glow effect to these lines. Any idea how to do that?

0

1 Answer 1

2

use UIBezierPath for draw line like below code...

You can init the UIBezierPath as following

    UIBezierPath *myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth=10;
    brushPattern=[UIColor redColor]; //This is the color of my stroke

Then you have Touch methods which handle and track the coordinates of your touch. When your touch begins on the screen, you ask UIBezierPath to move to that touch point

UITouch *mytouch=[[touches allObjects] objectAtInd
[myPath moveToPoint:[mytouch locationInView:self]];

As you move your finger around, you keep adding those points in your BezierPath in TouchMoved method by following

UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];

As we need constant refreshing of the screen, so that as soon as we draw it appears on the screen, we refresh the UIView subclass by calling following method in TouchMethod so that as soon as there any change in the BezierPath, it is reflected on the screen.

[self setNeedsDisplay];

Talking about drawRect Method which does all the drawing for you, you need to set the color of your stroke(stroke color means the color with which painting will be done on screen.) on screen and also the blend mode. You can try different blend mode and see the result.

- (void)drawRect:(CGRect)rect
{
    [brushPattern setStroke];
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];

}

also see this below link..

http://soulwithmobiletechnology.blogspot.in/2011/05/uibezierpath-tutorial-for-iphone-sdk-40.html

I hope this helps you...

:)

5
  • This is good to post links for references but only link is not good. Please post some relevant key code also with link. So is link will broke the code will be helpful
    – The iOSDev
    Oct 2, 2012 at 12:53
  • i know but this demo fulfill most of requirement of user so i give only direction... only for help ,Mate :) Oct 2, 2012 at 13:01
  • Thats ok I appreciate it. But, if you just copy past key method from that example it will be more appropriate and help the reader more :)
    – The iOSDev
    Oct 2, 2012 at 13:09
  • There you go then please put some key methods mate :) ;)
    – The iOSDev
    Oct 2, 2012 at 13:18
  • 2
    How do we GLOW the line? Dec 19, 2013 at 20:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.