Sunday, July 31, 2011

Set Colour of searchbar and NavigationBar

[self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:122.0f/255.0f green:165.0f/255.0f blue:156.0f/255.0f alpha:1]];
       
  [self.searchBar setTintColor:[UIColor colorWithRed:122.0f/255.0f green:165.0f/255.0f blue:156.0f/255.0f alpha:1]];
       

How to Customize slider and rotate to 90degrees....

   sliderTransform = YourSlider.transform;

    [YourSlider setFrame:CGRectMake(67.0f, 199.0f, 251.0f,10.0f)];

  YourSlider.transform = CGAffineTransformRotate(sliderTransform, 270.0/180*M_PI);



//This makes YourSlider to vertical

    YourSlider.backgroundColor = [UIColor clearColor];

UIImage *stetchTrack1 = [[UIImage imageNamed:@"blankimage.png"]stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
   
  [YourSlider setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"blueslider.png"]]];


  [YourSlider setThumbImage:[UIImage imageNamed:@"thumb.png"] forState:UIControlStateNormal];  //to set thumb image of Slider

    [YourSlider setMinimumTrackImage:stetchTrack1 forState:UIControlStateNormal];
    [YourSlider setMaximumTrackImage:stetchTrack1 forState:UIControlStateNormal];
   
    YourSlider.continuous = YES;

    [YourSlider setAccessibilityLabel:NSLocalizedString(@"CustomSlider", @"")];

    [self.view addSubview:YourSlider];

Add Done button on Numeric keyBorad....

- (void)textFieldDidBeginEditing:(UITextField *)textField{

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


- (void)keyboardWillShow {

 [self performSelector:@selector(addHideKeyboardButtonToKeyboard) withObject:nil afterDelay:0];
}


- (void)addHideKeyboardButtonToKeyboard {

 // Locate non-UIWindow.

    UIWindow *keyboardWindow = nil;

    UIView *keyboard;

  for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {


        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
 }



  if (!keyboardWindow) return;
   
    // Locate UIKeyboard. 
    UIView *foundKeyboard = nil;
    for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
       
        // iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
        if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
            possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
        }                                                                               
       
        if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
            foundKeyboard = possibleKeyboard;
            keyboard = possibleKeyboard;
           
            break;
        }
    }
   

if (foundKeyboard) {

        // Add the button to foundKeyboard.
  UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];

  doneButton.frame = CGRectMake(0, 163, 106, 53);

  doneButton.adjustsImageWhenHighlighted = NO;

  [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];

[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];




 [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
       
        // keyboard view found; add the custom button to it


        [keyboard addSubview:doneButton];
    }
   
}

//Now Removing Done button along with keyBoard

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
   
 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  

[self removeDoneButton];
   
 [textField resignFirstResponder];
   
    return YES;

}

-(void)removeDoneButton{
 
  UIWindow *keyboardWindow = nil;
    UIView *keyboard;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }
    if (!keyboardWindow) return;
   
    // Locate UIKeyboard. 

    UIView *foundKeyboard = nil;


    for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
            if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
           
                           possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
        }                                                                               
       
        if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
          

            foundKeyboard = possibleKeyboard;
            keyboard = possibleKeyboard;
           
            break;
        }
    }
   
    if (foundKeyboard) {
     
  // Add the button to foundKeyboard.

        UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];

        doneButton.frame = CGRectMake(0, 163, 106, 53);

        doneButton.adjustsImageWhenHighlighted = NO;
      [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
      [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
     
  [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
       
        // keyboard view found; add the custom button to it

        NSLog(@"keyboard description: %@", [keyboard description]);
     
  for (UIView *v in [keyboard subviews]) {

         if ([v isKindOfClass:NSClassFromString(@"UIButton")]) {

                [v removeFromSuperview];

               }
         }
     }
}