Showing posts with label iphone 4. Show all posts
Showing posts with label iphone 4. Show all posts

Wednesday, May 18, 2011

UIBezierPath tutorial for iPhone SDK 4.0 - Part 1


I was going through how to use UIBezierPath and what are its possible uses.. and I must say it is one hell of a convenient tool ! Ofcourse you can draw normal drawing with it as shown below and use your app as sketching pad in addition to that it adds so much convenience with the undo and redo action(will write that tutorial too next) that I fell in love with the use of UIBezierPath. You can have simple drawing as well as pattern based brush tip.   It is sooo easy to use this as pencil too that I don't even have words !





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 allObjectsobjectAtInd
    [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];

}








Pattern brush.. doesn't exactly work the way it is in Photoshop , because once you fill the whole screen with your drawing, the screen looks completely like a screen full of tiles of your pattern which is not what I would want but ... thats what we have so far in terms of pattern brush. I am trying to implement the brush with opengl lets see if I succeed then I will post it here !


myPath.lineWidth=10;//This can help you in setting width of your stroke/brush 
brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"pattern.jpg"]]; //You can set pattern in your color of your brush so that the strokes will appear with pattern of your image.


















































You can download the code HERE

Update:
Thanks to Sonia for pointing it out , wanted to know about smoothing of edges of bezier path, so that it doesn't look distorted . You can change the  capStyle of line for that. I have changed it and updated the code at above link.





















Well.. Finally implemented and uploaded code implementing Undo-Redo.
POSTED HERE




Very easy way to create pie charts in your iPhone app !

Well.. I haven't been across many pie chart creating APIs for iPhone/iPad app.. Here is my effort to make it as easy as I could for other developers looking to create pie chart in your app.

This post also makes clear the use of anti-alias stuff while you are drawing on your context.
The first pie chart diagram doesn't use the anti-alias but the second one does hence you can see in the screenshot attached with this post its looks so smooth ! For incorporating the anti-alias stuff  in your drawing you need to include only  2 lines as following:



CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);


If any one of them above is false then you will not have anti-alias work for you.

How to use this pie-chart code? 
In MainClass:
You will see following lines

myPieClass.itemArray=[[NSArray alloc]initWithObjects:@"12",@"84",@"44",@"55",@"100"nil];
myPieClass.myColorArray=[[NSArray alloc]initWithObjects:[UIColor purpleColor],[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor],[UIColor greenColor], nil];

So you give your own values to itemArray , code will automatically calculate the angle and offset  stuff for you. You also need to give the color for each segment of the pie chart. The number of items in myColorArray should be equal to number of items in itemArrayAnd according to above array values for color,  pie segment with value 12 have purple color, pie segment with value 84 will have red color.

Just to make it more clear: Suppose your created a budget application and you have 5 categories of expense type, 
now your total for category 1 is 12
total for category 2 is 84
total for category 3 is 44
total for category 4 is 55
total for category 5 is 100
  
So, you have to give here the raw values... in order to create your pie chart. Dont give angles value in itemArray as code calculates the angles itself as mentioned above.



As you can see in the picture below.



































NEW !!  MIM Chart library has been released in Alpha 1.0 version, It includes Line Graph, Bar Graph and many other kinds. You can find more info and download  HERE

Saturday, April 9, 2011

Recognize single and double tap on iPhone using UITapGestureRecognizer

If you have used elements like UIButton, UIImageView and you want to find out whether user tapped once or twice on it then you can do following and solve the problem very easily !

1. Create a subclass of UIButton or UIImageView whatever it is, in its implementation class you can define UITapGestureRecognizer methods like following:
























Then one of the following methods will be executed whenever a touch event is generated by user.You need to write these methods in the same file as above .













And your work is finished here now. You can just create an object of the class you have defined above and enjoy the single tap / double tap work like charm ... you dont need to code the hell out to recognise the single or double tap now !!














Thursday, March 24, 2011

How to reject Binary of your app on App Store ?

1. Login into your iTunes Connect Account @ https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa


2. Click Manage your Application. It will take you the list of the applications present on App Store. Select the app you want to reject the binary of. You will need to view the detail of the application. Then you will see following screen as shown below:  On this screen,you need to click on Binary Details.

3. Then you  will see following screen, where you can just press Reject This Binary.
 4. DONE ! Your status of the application will change to Developer Rejected the Binary with red dot !