1, When you edit with keyboard on ,click the background the keyboard will disappear
- (IBAction)backgroundClick:(id)sender { [nameField resignFirstResponder]; [numberField resignFirstResponder]; }
2, slider's value display by a label
- (IBAction)sliderChanged:(id)sender { UISlider *slider = (UISlider *)sender; int progressAsInt = (int)(slider.value + 0.5f); NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt]; sliderLabel.text = newText; [newText release]; }
3,Use Switch //value changed function
- (IBAction)switchChanged:(id)sender { UISwitch *whichSwitch = (UISwitch *)sender; BOOL setting = whichSwitch.isOn; [rightSwitch setOn:setting animated:YES]; }
4,Using Segmented Controller
- (IBAction)toggleShowHide:(id)sender { UISegmentedControl *segmentedControl = (UISegmentedControl *)sender; NSInteger segment = segmentedControl.selectedSegmentIndex; if (segment == kShowSegmentIndex) [switchView setHidden:NO]; else [switchView setHidden:YES]; }
5,USing Operation Table and Alert
- (IBAction)doSomething:(id)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure?" delegate:self cancelButtonTitle:@"No Way!" destructiveButtonTitle:@"Yes, I'm Sure!" otherButtonTitles:nil]; [actionSheet showInView:self.view]; [actionSheet release]; } - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { if (!buttonIndex == [actionSheet cancelButtonIndex]) { NSString *msg = nil; if (nameField.text.length > 0) msg = [[NSString alloc] initWithFormat:@"breathe easy, %@, OK.",nameField.text]; else msg = @"breathe easy, OK."; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something was done" message:msg delegate:self cancelButtonTitle:@"Phew!" otherButtonTitles:nil]; [alert show]; [alert release]; [msg release]; } }
6,Using beauty button
- (void)viewDidLoad { UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"]; UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; [doSomethingButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal]; UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"]; UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0]; [doSomethingButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted]; }