Wednesday 27 March 2013

Draw Road Line in Map of source to destination lat and long


 NSString *Source_latlong = @"25.4500,81.8500";
    NSString *Destination_mylatlong = @"26.9200,75.8200";


    [[UIApplication sharedApplication] openURL:
     [NSURL URLWithString:
      [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%@&daddr=%@",
      Source_latlong ,
       Destination_mylatlong]]];

Tuesday 26 March 2013

how to go one textField to next textField respective/programmatically how to to go when we click next button on keyboar then go next textfield in iphone/How to navigate through textfields (Next / Done Buttons)


-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
    NSInteger nextTag = textField.tag + 1;
    // Try to find next responder
    UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
    if (nextResponder) {
        
        // Found next responder, so set it.
        [nextResponder becomeFirstResponder];
    } else {
        // Not found, so remove keyboard.
        [textField resignFirstResponder];
    }
    return NO; // We do not want UITextField to insert line-breaks.
}
...............................................OR.............................


-(BOOL) textFieldShouldReturn: (UITextField *) theTextField {
int tag = theTextField.tag + 1;
[[self.view viewWithTag:tag] becomeFirstResponder];
return NO;
}

...............................NOTE....................
1-Don't forgot textField connect delegate to File Owner and to give respective tag  value of textfield 
  for ex..1,2,3,4,5,6...

Monday 25 March 2013

Remove keyboard , while textField create on custom alertView


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if ([textField isFirstResponder])
    {
        
    [textField resignFirstResponder];
    NSLog(@"text field was first responder");
    }
    
    else
    {
        [textField becomeFirstResponder];
        [textField resignFirstResponder];
        NSLog(@"text field was not first responder");
    }
    NSLog(@"textfieldshouldreturn");
    return YES;
}

Friday 22 March 2013

Show User Library Directory in Mac OS X 10.7 Lion & 10.8 Mountain Lion


Mac OS X 10.7 & OS X 10.8 defaults to hiding the users Library directory, this is probably to keep people from accidentally deleting or damaging files that are necessary for OS X Lion to function properly. That is fine for novice users, but for some of us, we want to be able to access ~/Library/ at will. A visible Library folder was also the default setting in past versions of Mac OS X, here is how to get this back.

Show User ~/Library in OS X Lion & Mountain Lion

Launch Terminal from Spotlight or Launchpad -> Utilities, and enter the following command to show or hide the directory:
chflags nohidden ~/Library/
The users Library folder will immediately become visible again. Reverting this back to the standard Lion setting is simple too:

Hide User ~/Library in OS X Lion (default setting)

This returns to the default setting of hiding the user Library directory:
chflags hidden ~/Library
Changes take effect immediately again, and Library becomes invisible to the user.

Monday 18 March 2013

how to make textfield on click show date picker and picker view with toolbar in iphone sdk


- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    [textField resignFirstResponder];
   
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
   
    [textField resignFirstResponder];
   
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    //    [textField setInputAccessoryView:keyboardToolbar];
    if (textField==txtDate) {
        [txtDate resignFirstResponder];
        //        txtDate.inputView = datePickerl;
        [self showDate];
        }
    else if(textField==txtTime) {
        [txtTime resignFirstResponder];
        isPicker = true;
        [self showPicker];
        }
    else if (textField==txtCountry) {
        [txtCountry resignFirstResponder];
        isPicker=false;
        [self showPicker];
        }
    else if(textField==txtVanue) {
        [scrollView setContentOffset:CGPointMake(0, 100) animated:YES];
    }
    else if (textField==txtCountry) {
        [scrollView setContentOffset:CGPointMake(0, 120) animated:YES];
    }
}

- (void)LabelChange:(id)sender{
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateStyle = NSDateFormatterMediumStyle;
    txtDate.text = [NSString stringWithFormat:@"%@",
                       [df stringFromDate:datePicker.date]];
}

-(void)showDate{
    menu = [[UIActionSheet alloc] initWithTitle:@"Select Date"
               delegate:self
               cancelButtonTitle:nil
               destructiveButtonTitle:nil
               otherButtonTitles:nil];
   
    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
    datePicker.datePickerMode = UIDatePickerModeDate;
    datePicker.minimumDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]autorelease]];
    [dateFormatter setDateFormat:@"dd MMM yyyy"];
    //[dateFormatter setDateFormat:@"MM/dd/YYYY"];
   
    //[theDatePicker release];
    [datePicker addTarget:self action:@selector(LabelChange:) forControlEvents:UIControlEventValueChanged];
   
   
    dateTool = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    dateTool.barStyle=UIBarStyleBlackOpaque;
    [dateTool sizeToFit];
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick)];
    [barItems addObject:flexSpace];
   
    [dateTool setItems:barItems animated:YES];
    [menu addSubview:dateTool];
    [menu addSubview:datePicker];
    [menu showInView:self.view];
    [menu setBounds:CGRectMake(0,0,320, 464)];
   
   
    //    [self.view addSubview:datePicker];
   
    [datePicker release];
}
-(IBAction)DatePickerDoneClick{
    [menu dismissWithClickedButtonIndex:0 animated:YES];
}

-(void)showPicker{
    menu = [[UIActionSheet alloc] initWithTitle:@"Select Time"
               delegate:self
               cancelButtonTitle:nil
               destructiveButtonTitle:nil
               otherButtonTitles:nil];
   
    pickerView=[[UIPickerView alloc] init];
    pickerView.frame= CGRectMake(0.0, 44.0, 0.0, 0.0);
    pickerView.delegate=self;
    pickerView.dataSource=self;
    pickerView.showsSelectionIndicator = YES;
    txtTime.inputView=pickerView; 
   
    dateTool = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    dateTool.barStyle=UIBarStyleBlackOpaque;
    [dateTool sizeToFit]; 
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick)];
    [barItems addObject:flexSpace];
   
    [dateTool setItems:barItems animated:YES];
    [menu addSubview:dateTool];
    [menu addSubview:pickerView];
    [menu showInView:self.view];
    [menu setBounds:CGRectMake(0,0,320, 464)];
    [pickerView release];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (isPicker==true) {
        return [arrTime count];
        }
    else {
        return [arrCountry count];
        }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (isPicker==true) {
        return [arrTime objectAtIndex:row];
        }
    else {
        return [arrCountry objectAtIndex:row];
        }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (isPicker==true) {
        txtTime.text = [arrTime objectAtIndex:row];
        }
    else {
        txtCountry.text = [arrCountry objectAtIndex:row];
        }
   
}

How to set checkbox in iphone sdk?



if u want to choose only one selected of twos using following line of code......

 IBOutlet UIButton *btnCheckBox1;
    IBOutlet UIButton *btnCheckBox2;

 btnCheckBox1.tag = 1;
    btnCheckBox2.tag = 2;
[btnCheckBox1 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
     [btnCheckBox2 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];

-(IBAction)btnCheckboxClicked:(id)sender{
 UIButton *selectedButton = (UIButton *)sender;
    UIButton    *toggledButton;
   
    if (selectedButton.tag == 1 ) {
        toggledButton =    btnCheckBox1;
         [btnCheckBox1 setImage:[UIImage imageNamed:@"active-checkbox.png"] forState:UIControlStateNormal];
        strType = lblEmployee.text;
    }
    else {
        [btnCheckBox1 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
    }
    if (selectedButton.tag == 2 ) {
        toggledButton =    btnCheckBox2;
        [btnCheckBox2 setImage:[UIImage imageNamed:@"active-checkbox.png"] forState:UIControlStateNormal];
        strType = lblEmployers.text;
    }
    else {
        [btnCheckBox2 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];

    }
    [toggledButton    setSelected:NO];
    [sender setSelected:YES];
}

how text length of a UITextView can be fixed in iphone sdk?



- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    NSUInteger newLength = (text_View.text.length - range.length) + text.length;
    if(newLength <= 140)
    {
        return YES;
    } else {
        NSUInteger emptySpace = 140 - (text_View.text.length - range.length);
        textView.text = [[[textView.text substringToIndex:range.location
                          stringByAppendingString:[text substringToIndex:emptySpace]]
                         stringByAppendingString:[textView.text substringFromIndex:(range.location+ range.length)]];
        return NO;
    }
}

Push Notification in iphone sdk

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [NSThread sleepForTimeInterval:5.0];
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    
    self.viewController = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
    
    [self.window addSubview:navControll.view];
    [self.window makeKeyAndVisible];
    
    NSLog(@"Initiating remoteNoticationssAreActive"); 
    // / Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    
    // UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    //[self sendProviderDeviceToken];
    NSLog(@"%@",[[[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"aps"] objectForKey:@"alert"]);
    
    
    return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    //NSLog(@"selected is %@",viewController);
    
    if(tabBarController.selectedViewController)
    {
        NSLog(@"selected is %@",tabBarController.selectedViewController);
    }
    
    
    NSArray *vc= tabBarController.viewControllers;
    for (int i = 0; i < [vc count]; i++) {
        UINavigationController *nc = [vc objectAtIndex:i];
        if (nc == tabBarController.selectedViewController) {
            continue;
        }
        [nc popToRootViewControllerAnimated:NO];
    }
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    
    NSString *str = [NSString 
                        stringWithFormat:@"Device Token=%@",deviceToken];
    NSLog(@"%@",str);
    
    str = [[[deviceToken description] 
              stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@""]] 
              stringByReplacingOccurrencesOfString:@" " withString:@""];;
    NSLog(@"Device Token : %@", str);
    ///c7dc86e8376a46825c98a7d4aa48c8d46d43025798ee2ac85fe97b47488c4a88
    NSLog(@"Remote type : %d", [[UIApplication sharedApplication] enabledRemoteNotificationTypes]);
    
    
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(@"%@",str); 
    
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    // for (id key in userInfo) {
    // NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
    // } 
    NSLog(@"Received Notification");
    NSLog(@"remote notification: %@",[userInfo description]);
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    
    NSString *alert = [apsInfo objectForKey:@"alert"];
    NSLog(@"Received Push Alert: %@", alert);
    
    NSString *sound = [apsInfo objectForKey:@"sound"];
    NSLog(@"Received Push Sound: %@", sound);
    
    NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);
    application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
    
    
}

how to make TabBar in iphone sdk

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    
    imgBackground.image =[UIImage imageNamed:@"splash.png"];
    
    appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    tab=[[UITabBar alloc]initWithFrame:CGRectMake(0.0, 412,self.view.bounds.size.width, 49.0)];
    tab.delegate=self;
    
    [self.view addSubview:tab];
    [self createTabBarItems];
    

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)createTabBarItems{    
    
      tbEvent =[[UITabBarItem alloc] initWithTitle:@"Event" image:[UIImage imageNamed:@"latest.png"] tag:0]; 
    
    tbAbout = [[UITabBarItem alloc] initWithTitle:@"AboutUs" image:[UIImage imageNamed:@"about.png"] tag:1];
    
    tbContact = [[UITabBarItem alloc] initWithTitle:@"ContactUs" image:[UIImage imageNamed:@"contact.png"] tag:2];
    
    tab.items =[[NSArray arrayWithObjects:tbEvent,tbAbout,tbContact,nil] retain];
    
    [self.view addSubview:tab];
    
    [tab release];
    
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{ 
    
      if(tabBar.selectedItem.tag == 0)
    {
       // appDel.activityView.hidden = NO;
        EventViewController *eventView = [[EventViewController alloc] initWithNibName:@"EventViewController" bundle:nil];
        [self.navigationController pushViewController:eventView animated:NO];
        [eventView release];
    }
    if (tabBar.selectedItem.tag == 1) {
        
        AboutUsViewController *aboutView = [[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];
        [self.navigationController pushViewController:aboutView animated:NO];
        [aboutView release];
    }
    if (tabBar.selectedItem.tag == 2) {
        ContactUsViewController *contactView = [[ContactUsViewController alloc] initWithNibName:@"ContactUsViewController" bundle:nil];
        [self.navigationController pushViewController:contactView animated:NO];
        [contactView release];
    }
    
}

For changing the color of the UITabBarItem text in iphone

[[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor blackColor], UITextAttributeTextColor, 
      [UIColor grayColor], UITextAttributeTextShadowColor, 
      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
      [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, 
      nil] 
                                             forState:UIControlStateNormal];

Friday 15 March 2013

Disable Past Date in UIDatePicker






 UIDatePicker *datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 40, 320, 216)];
 datePicker.datePickerMode = UIDatePickerModeDate;
 datePicker.hidden = NO;
 [datePicker setMinimumDate: [NSDate date]];//Disable Past Date in UIDatePicker

How to make splash screen animation in iphone sdk

- (void)loadView
{
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
   
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        _animationBookCoverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
    }
    else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {         
        if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
        {
            _animationBookCoverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Landscape.png"]];           
        }
        else
        {
            _animationBookCoverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Portrait.png"]];
        }
    }
   
    // Offset by the status bar on iPad. We don't on iPhone because splashscreens take up the full height.
    // No idea why Apple did this differently for iPhone and iPad.
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        _animationBookCoverView.frame = CGRectMake(0, 20,
                                                   _animationBookCoverView.frame.size.width,
                                                   _animationBookCoverView.frame.size.height);
    }
   
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    self.view.backgroundColor = [UIColor clearColor];
    _animationBookCoverView.backgroundColor = [UIColor clearColor];
   
    [self.view addSubview:_animationBookCoverView];
   
    // Credit to this smart cookie:
    // http://mo7amedfouad.com/2011/12/book-cover-flip-animation-like-in-path-app/
   
    _animationBookCoverView.layer.anchorPoint = CGPointMake(0, .5);
    _animationBookCoverView.center = CGPointMake(_animationBookCoverView.center.x - _animationBookCoverView.bounds.size.width/2.0f, _animationBookCoverView.center.y);
    [UIView beginAnimations:@"openBook" context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView setAnimationDuration:3.0];
    [UIView setAnimationDelay:0];
    CATransform3D _3Dt = CATransform3DIdentity;
    _3Dt = CATransform3DMakeRotation(M_PI/2.0, 0.0f, -1.0f, 0.0f);
    _3Dt.m34 = 0.001f; // Perspective
   
    _animationBookCoverView.layer.transform = _3Dt;
    [UIView commitAnimations];
   
    // Super hack. Adding a view to the window in Landscape on an iPad just doesn't work.
    // Used this guy's approach to manually rotate it:
    // http://stackoverflow.com/questions/1484799/only-first-uiview-added-view-addsubview-shows-correct-orientation/2694563#2694563
    // And then I learned that LandscapeLeft and PortraitUpsideDown need to be rotated an extra 180
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        CGAffineTransform rotate;
       
        if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            rotate = CGAffineTransformMakeRotation(M_PI/2.0);
        }
        else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        {
            rotate = CGAffineTransformMakeRotation(M_PI);
        }
        else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        {
            rotate = CGAffineTransformMakeRotation(1.5 * M_PI);
        }
        else
        {
            // UIInterfaceOrientationPortrait - Only one that works without hacks
            return;
        }
       
        [self.view setTransform:rotate];
        self.view.frame = CGRectMake(0, 0, 1024, 768);
    }
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag context:(void *)context
{
    [self.view removeFromSuperview];
}