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.