Tuesday, September 27, 2011

MIM ChartLib version 1.2

Thanks to Michael Lau Ka Wai for pointing it out.


Now the graph appears only within valid range instead of starting from 0 unless user specifies it. In version 1.2, its available only in LineGraph. I will add the same functionality to other graphs as well. You can see the changes if you run HowToUseFiles>TestLineClass as rootcontroller. 

Link to Version 1.2 on DropBox

Tuesday, September 20, 2011

Job Post

One of my friend(IITK Almuni) is starting an interesting product company in Bangalore. Please contact him if you are interested.


iOS programmer needed for a startup in Bangalore. Contact mihir.mohan@gmail.com for details.

Wednesday, September 14, 2011

Customize your UIKeyboard with toolbar

So you are looking to put a toolbar on top of your keyboard with bunch of button on it as shown in the screenshot below.

The toolbar view will be attached with as inputAccessoryView of the textfield or textview.




















Important code snippets can be seen here. You can download the complete code below with the link.


//One main thing you need to do is add the notification for showing and hiding keyboard


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];


//Next thing is to add the toolbarview as accessoryview. Here I am loading it off the nib file.


[[NSBundle mainBundle] loadNibNamed:@"AccessoryView" owner:self options:nil];
textView.inputAccessoryView = accessoryView;  //Make sure you have connection as in sample code.


//Notification Handlers

- (void)keyboardWillShow:(NSNotification *)notification {
    
  

    NSDictionary *userInfo = [notification userInfo];
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

   
    CGRect keyboardRect = [aValue CGRectValue];
    keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
    
    CGFloat keyboardTop = keyboardRect.origin.y;
    CGRect newTextViewFrame = self.view.bounds;
    newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;
    

    NSValue *animationDurationValue = [userInfo     objectForKey:UIKeyboardAnimationDurationUserInfoKey];    
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:animationDuration];
    
    textView.frame = newTextViewFrame;

    [UIView commitAnimations];
}


- (void)keyboardWillHide:(NSNotification *)notification {
    
    NSDictionary* userInfo = [notification userInfo];

    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:animationDuration];
    
    textView.frame = self.view.bounds;
    
    [UIView commitAnimations];
}




You can download the code HERE

Saturday, September 10, 2011

Customized AlertView

In this post, we will learn, How to

1. Change the frame size of UIAlertView
2. Change the frame/Location of buttons on UIAlertView
3. Align the Title label of UIAlertView in center.

Check the method below in code  willPresentAlertView

And don't forget to write - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  to handle the button click event of UIAlertview buttons.




- (void)willPresentAlertView:(UIAlertView *)alertView {
    
    

    if(alertView.tag==10)
    {
        //Set the frame size of Alertview
        alertView.frame = CGRectMake((1024-350)/2, (748-300)/2, 350, 200);
        
        //Align the title label
        UILabel *theTitle = [alertView valueForKey:@"_titleLabel"];
        theTitle.center=CGPointMake(170, 20);
        
        //Set the frame/location of buttons on alertview
        UIButton *cancelButton=[(NSMutableArray*)[alertView valueForKey:@"_buttons"] objectAtIndex:0];
        cancelButton.frame=CGRectMake(12, 125, 100, 45);
        
        UIButton *saveButton=[(NSMutableArray*)[alertView valueForKey:@"_buttons"] objectAtIndex:1];
        saveButton.frame=CGRectMake(124, 125, 100, 45);
        
        UIButton *laterButton=[(NSMutableArray*)[alertView valueForKey:@"_buttons"] objectAtIndex:2];
        laterButton.frame=CGRectMake(236, 125, 100, 45);


    }
    
}





-(void)showCustomizedAlertView
{

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter your Info" message:@"\n\n\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save",@"Later" ,nil];
    alertView.tag=10;
    
    
    UILabel *labelA1=[[UILabel alloc]initWithFrame:CGRectMake(25,49,63,23)];
    [labelA1 setBackgroundColor:[UIColor clearColor]];
    [labelA1 setTextColor:[UIColor whiteColor]];
    [labelA1 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
    [alertView addSubview:labelA1];
    
    UILabel *labelA2=[[UILabel alloc]initWithFrame:CGRectMake(25,85,63,23)];
    [labelA2 setBackgroundColor:[UIColor clearColor]];
    [labelA2 setTextColor:[UIColor whiteColor]];
    [labelA2 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
    [alertView addSubview:labelA2];
    
    UILabel *labelA3=[[UILabel alloc]initWithFrame:CGRectMake(195,85,63,23)];
    [labelA3 setBackgroundColor:[UIColor clearColor]];
    [labelA3 setTextColor:[UIColor whiteColor]];
    [labelA3 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
    [alertView addSubview:labelA3];
    
    
    UILabel *labelA4=[[UILabel alloc]initWithFrame:CGRectMake(195,49,63,23)];
    [labelA4 setBackgroundColor:[UIColor clearColor]];
    [labelA4 setTextColor:[UIColor whiteColor]];
    [labelA4 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
    [alertView addSubview:labelA4];
    
    
    
    [labelA1 setText:@"Name"];
    [labelA2 setText:@"Age"];
    [labelA3 setText:@"Sex"];
    [labelA4 setText:@"City"];
    
    [labelA1 release];
    [labelA2 release];
    [labelA3 release];
    [labelA4 release];
    
    //Add Them
    alertTextField = [[UITextField alloc] initWithFrame:CGRectMake(92, 50, 80, 25)];
alertTextField.borderStyle = UITextBorderStyleRoundedRect;
alertTextField.backgroundColor = [UIColor clearColor];
alertTextField.placeholder = @" ";
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
    alertTextField.returnKeyType=UIReturnKeyDone;
[alertView addSubview:alertTextField];
[alertTextField becomeFirstResponder];
    
    
    alertTextField2 = [[UITextField alloc] initWithFrame:CGRectMake(92, 84, 80, 25)];
alertTextField2.borderStyle = UITextBorderStyleRoundedRect;
alertTextField2.backgroundColor = [UIColor clearColor];
alertTextField2.placeholder = @" ";
alertTextField2.keyboardType = UIKeyboardTypeNumberPad;
    alertTextField2.returnKeyType=UIReturnKeyDone;
[alertView addSubview:alertTextField2];
    
    
    
    alertTextField3 = [[UITextField alloc] initWithFrame:CGRectMake(245, 84, 80, 25)];
alertTextField3.borderStyle = UITextBorderStyleRoundedRect;
alertTextField3.backgroundColor = [UIColor clearColor];
alertTextField3.placeholder = @" ";
alertTextField3.keyboardType = UIKeyboardTypeNumberPad;
    alertTextField3.returnKeyType=UIReturnKeyDone;
[alertView addSubview:alertTextField3];
    
    
    
    alertTextField4 = [[UITextField alloc] initWithFrame:CGRectMake(245, 50, 80, 25)];
alertTextField4.borderStyle = UITextBorderStyleRoundedRect;
alertTextField4.backgroundColor = [UIColor clearColor];
alertTextField4.placeholder = @" ";
alertTextField4.keyboardType = UIKeyboardTypeNumberPad;
    alertTextField4.returnKeyType=UIReturnKeyDone;
[alertView addSubview:alertTextField4];
    
    
    [alertView show];
    [alertView release];
    
}

Output looks like following:













Thursday, September 8, 2011

Back !

I was away on a trip for something important. Now am back blogging. Keep checking for new posts.


Monday, August 29, 2011

MIMChart Library Update 1.1



Here is a complete GUIDE of all classes, it is still under construction but its detailed. LINK



So kindly  fetch the new and updated version from GitHub/Dropbox.

Link to Download ON GITHUB





Created a READ ME, to make it clear how to make use of it.


------------------------------------------------------------------------------------


This is a project (Opensource library)of chart libraries which can used in iPhone/iPads.
Charts available:
1.Line Graph
2.Wall Graph
3.Bar Graph
4.Fragmented Bar Graph
5.Pie Chart
6.Fragmented Pie Chart
7.Cluster Chart


Complete Guide can be found HERE


--------------------------------------------------------------
HOW TO USE IT IN YOUR CODE
--------------------------------------------------------------
1. Add 2 frameworks for sure (QuartzCore and CoreText)
2. Copy and Paste "Lib Files" folder in your project and Also add them to your project by right clicking your project in XCode and choose "Add files to your project". Note "Lib Files" folder can be found under MIMChartLib > "Lib Files" in MIMChart Project.

3. Add the .csv file (Data file) to the project as well from which you will be reading the data. Check the sample codes to find out about csv data files OR go to GUIDE link provided above.

4. Then you can add the chart of your purpose to your view in your app.

To find out more about how to stick the chart in your view please see the sample codes.
--------------------------------------------------------------
HOW TO RUN THE SAMPLE CODES IN THE LIBRARY.
--------------------------------------------------------------
1. Go to MIMChartLibAppDelegate.m in MIMChartLib folder in XCode.

2. You will see various rootControllers. You can comment/uncomment one by one  and RUN the code to see what they look like.
You can go to those Test Classes like TestClass,TestClassFragmented etc available in HowToUseFiles folder to get more idea.

--------------------------------------------------------------
AND you can find more info on HERE

MIM Chart Library version Alpha 1.0 Released !


Finally, its uploaded on GitHub.
You can find all related sample code, sample visuals and documentation HERE 

Complete Guide for Pie Chart and Fragmented Pie Chart (MIM Chart Lib)

So our data looks like following and we will make pie chart of the Income column.
Code is in XCode proj > HowToUseFiles> TestClass.m

     [MIMColor InitColors];

    NSString *csvPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTable.csv"];
    MIMPieChart *pieChartView=[[MIMPieChart alloc]initWithFrame:CGRectMake(40, 40, 600, 500)];
    pieChartView.radius=200;
    pieChartView.tint=BEIGETINT;// Available Tints: GREENTINT,REDTINT,BEIGETINT
    [pieChartView readFromCSV:csvPath  TitleAtColumn:0  DataAtColumn:4];
    [pieChartView drawPieChart];
    [self.view addSubview:pieChartView];



It will make the pie chart look like following, you can change the tint color to see what they look like OR you can GO TO THIS POST to see them. If you tap on a region of pie chart, the respective information label gets highlighted, as in this case Indonesia is highlighted.



























Now lets look at fragmented piechart , for now we can give data only through arrays, I need to add support for csv format. But you can use it as following as in XCode proj > HowToUseFiles> TestClassFragmented.m


      [MIMColor InitColors];
    
    _DFragmentedDoughNut *detailedDoughNut=[[_DFragmentedDoughNut alloc]initWithFrame:CGRectMake(0, 0, 600, 600)];
    detailedDoughNut.tint=GREENTINT;// Available Tints: GREENTINT,REDTINT,BEIGETINT
    detailedDoughNut.isShadow=YES;
    [detailedDoughNut setValuesArray:[NSArray arrayWithObjects:@"23",@"45",@"89",@"123",@"21",@"144", nil]];
    [detailedDoughNut setTitleArray:[NSArray arrayWithObjects:@"U.P.",@"Bihar",@"Delhi",@"Punjab",@"Haryana",@"Rajasthan", nil]];
    [detailedDoughNut setOutRadius:200 AndInnerRadius:300];
    [self.view addSubview:detailedDoughNut];
    
Output looks like following






























Entire Guide can be found HERE along with downloadables.

Complete Guide for Wall Graph (MIM Chart Lib)

Following is our data and we want to plot Months Vs. Income

Our code residing in XCode Project > HowToUseFiles > WallTestClass.m

      [MIMColor InitFragmentedBarColors];
    
    
    NSString *csvPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTable1.csv"];
    WallGraph *wallGraph=[[WallGraph alloc]initWithFrame:CGRectMake(50, 40, 600, 400)];
    wallGraph.xIsString=YES;//For Now only xIsString=YES is supported.
    wallGraph.isGradient=YES;
    wallGraph.isShadow=YES;
    wallGraph.style=14;
    wallGraph.needStyleSetter=YES;
    wallGraph.anchorType=NONE;
    [wallGraph readFromCSV:csvPath  TitleAtColumn:0  DataAtColumn:4];
    [wallGraph displayYAxis];
    [wallGraph drawWallGraph];
    [self.view addSubview:wallGraph];
    

So our result looks like following

























--------------------------------------------------------------------------------------------------------------------------------------------
The setting as shown in the code below will give result as shown in screenshot just below the code

       wallGraph.isGradient=YES;
    wallGraph.isShadow=NO;
    wallGraph.style=14;
    wallGraph.needStyleSetter=YES;
    wallGraph.anchorType=CIRCLEBORDER;


























--------------------------------------------------------------------------------------------------------------------------------------------
Tapping on the Anchor points, will display the corresponding data of the point.

       wallGraph.isGradient=YES;
    wallGraph.isShadow=YES;
    wallGraph.style=14;
    wallGraph.needStyleSetter=YES;
    wallGraph.anchorType=CIRCLEBORDER;



























--------------------------------------------------------------------------------------------------------------------------------------------

       wallGraph.isGradient=YES;
    //wallGraph.isShadow=YES;
    //wallGraph.style=14;
    wallGraph.needStyleSetter=YES;
    wallGraph.anchorType=CIRCLEFILLED;



























--------------------------------------------------------------------------------------------------------------------------------------------

       wallGraph.isGradient=YES;
    //wallGraph.isShadow=YES;
    //wallGraph.style=14;
    wallGraph.needStyleSetter=YES;
    wallGraph.anchorType=NONE;DE




























--------------------------------------------------------------------------------------------------------------------------------------------

       wallGraph.isGradient=YES;
    //wallGraph.isShadow=YES;
    //wallGraph.style=14;
    wallGraph.needStyleSetter=YES;
    wallGraph.anchorType=DEFAULT;



























--------------------------------------------------------------------------------------------------------------------------------------------
NOTE: wallGraph.needStyleSetter=NO; For remove the NEXT button on the screen.


Entire Guide can be found HERE along with downloadables.

Complete Guide for Line Chart Chart (MIM Chart Lib)

So our data sheet looks like following screenshot which I want to plot using MIM Chart lib - Line Graph. We want to plot Per Capita Income of India, USA, China, Germany yearwise.









If you don't give which column specifically you want to draw,give value of valueColumnsinRange  as nil , It will plot all the columns on the Line graph.

      [MIMColor InitColors];
    NSString *csvPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTable2.csv"];

    LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:CGRectMake(50, 40, 600, 400)];
    lineGraph.needStyleSetter=YES;
    lineGraph.xIsString=YES
    lineGraph.anchorType=CIRCLEFILLED; //VIEW OTHER anchorType
    [lineGraph readFromCSV:csvPath valueColumnsinRange:nil]; 
    [lineGraph displayYAxis];
    [lineGraph displayXAxisWithStyle:3]; //VIEW OTHER styles FOR X-Axis Labels
    [lineGraph drawWallGraph];
    [self.view addSubview:lineGraph];


Result:


------------------------------------------------------------------------------------------------------------------------------------------------

If you give which column specifically you want to draw,give value of valueColumnsinRange  as [NSArray arrayWithObjects:@"1",@"3", nilwill have array of all valid columns you want to draw , It will plot those the columns on the Line graph.



      [MIMColor InitColors];

    NSString *csvPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTable2.csv"];
    LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:CGRectMake(50, 40, 600, 400)];
    lineGraph.needStyleSetter=YES;
    lineGraph.xIsString=YES
    lineGraph.anchorType=DEFAULT //OTHER anchorType
    [lineGraph readFromCSV:csvPath valueColumnsinRange:[NSArray arrayWithObjects:@"1",@"3", nil]];
    [lineGraph displayYAxis];
    [lineGraph displayXAxisWithStyle:3]; //OTHER styles FOR X-Axis Labels
    [lineGraph drawWallGraph];
    
    [self.view addSubview:lineGraph];



-------------------------------------------------------------------------------------------------------------------------------------------------------
If you have data sheet with x and y int values only as shown in this sheet. You want to plot x Vs. y, x Vs. y1 and x Vs. y2.






You can use following code. You give array of columns for x-axis separately and array of columns for y-axis values separately. Its important to have same number of elements in array for x-axis and y-axis.

      [MIMColor InitColors];
    NSString *csvPath2 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTableLinesWithIntOnly.csv"];
    
    LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:CGRectMake(50, 40, 600, 400)];
    lineGraph.needStyleSetter=YES
    lineGraph.xIsString=NO
    lineGraph.anchorType=SQUAREFILLED //OTHER anchorType
    [lineGraph readFromCSV:csvPath2 xInColumn:[NSArray arrayWithObjects:@"0",@"0",@"0", nil] yInColumn:[NSArray arrayWithObjects:@"1",@"2",@"3", nil]];
    [lineGraph displayYAxis];
    [lineGraph displayXAxisWithStyle:3]; //OTHER styles FOR X-Axis Labels
    [lineGraph drawWallGraph];
    [self.view addSubview:lineGraph];
    





-------------------------------------------------------------------------------------------------------------------------------------------------
If you have data sheet of following type where you want to plot Month Vs. Income and Month Vs. Expense on the same line graph.


Following code will give you output as shown in the screenshot below.

      [MIMColor InitColors];
    NSString *csvPath1 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTableBar.csv"];    
    LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:CGRectMake(50, 40, 600, 400)];
    lineGraph.needStyleSetter=YES;
    lineGraph.xIsString=YES
    lineGraph.anchorType=CIRCLEBORDER //OTHER anchorType
    [lineGraph readFromCSV:csvPath1 titleAtColumn:0 valueInColumn:[NSArray arrayWithObjects:@"4",@"8", nil]];
    [lineGraph displayYAxis];
    [lineGraph displayXAxisWithStyle:3]; //OTHER styles FOR X-Axis Labels
    [lineGraph drawWallGraph];
    
    [self.view addSubview:lineGraph];

Resulting output view



-----------------------------------------------------------------------------------------------------------------------------------------------
More details about the code used above in XCode project> HowToUseFiles > TestLineClass.m :



       /*
     
     Line Graph supports array of plain colors only.
     Gradient colors are not supported yet.
     
     */
    [MIMColor InitColors];
    
    
    /*These are 3 different types of data files which can be read by MIM Lib to create Line Graph*/
    NSString *csvPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTable2.csv"];
    NSString *csvPath1 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTableBar.csv"];
    NSString *csvPath2 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTableLinesWithIntOnly.csv"];
    
    LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:CGRectMake(50, 40, 600, 400)];
    
    
    /*
     
     If YES this will display the style setting button. Keep clicking on Next button to view next color pattern.
     Once you like a particular color combination,
     you can feed that number to lineGraph.style in next line of code and set needStyleSetter NO for release version
     It is provided only to help developer get better visualization of his chart in real time development
     */
    
    lineGraph.needStyleSetter=YES;
    
     /* 
     This is basically the INDEX of color object in your COLOR ARRAY
     THis is the color of lines which will be displayed on the line graph
    It can be any index number of your array.Note it goes in the loop.
     */
    lineGraph.style=10; 
    
    
    
    //NO only for third kind of data file(csvPath2) otherwise YES
    //lineGraph.xIsString=YES; 
    lineGraph.xIsString=NO
    
    
    
    /*
     
     SQUAREFILLED,
     SQUAREBORDER,
     CIRCLEFILLED,
     CIRCLEBORDER,
     DEFAULT,
     NONE.
     
     If you don't define it, By default it will be CIRCLEBORDER
     
     */
    lineGraph.anchorType=NONE;
    

    //case 1.1:
    //[lineGraph readFromCSV:csvPath valueColumnsinRange:nil];
    
    //case 1.2:
    //[lineGraph readFromCSV:csvPath valueColumnsinRange:[NSArray arrayWithObjects:@"1",@"3", nil]];
    
    
    //case 2:
    //[lineGraph readFromCSV:csvPath1 titleAtColumn:0 valueInColumn:[NSArray arrayWithObjects:@"4",@"8", nil]];
    
    
    //case 3:
    //Note [xInColumn array count]= [yInColumn array count], As the MIM Chart Lib maps x and y values in them.
    [lineGraph readFromCSV:csvPath2 xInColumn:[NSArray arrayWithObjects:@"0",@"0",@"0", nil] yInColumn:[NSArray arrayWithObjects:@"1",@"2",@"3", nil]];
    
    
    
    //If you want to display the values on x axis.
    [lineGraph displayYAxis];
    
    /* 3 styles exist for x-axis labels (1,2 and 3)*/
    /*If you don't want to display labels on x-axis, comment this line*/
    /*To find out what different styles looks like refer to following post: */
    [lineGraph displayXAxisWithStyle:3];
    
    
    //Finally draw them
    [lineGraph drawWallGraph];
    
    [self.view addSubview:lineGraph];


Entire Guide can be found HERE along with downloadables.