Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created October 24, 2012 05:08
Show Gist options
  • Save ChrisRisner/3944063 to your computer and use it in GitHub Desktop.
Save ChrisRisner/3944063 to your computer and use it in GitHub Desktop.
ios Day 9
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if (textView == self.txtView) {
NSInteger newTextLength = [textView.text length] - range.length + [text length];
if (newTextLength > 45) {
return NO;
}
}
return YES;
}
- (BOOL) textFieldShouldEndEditing:(UITextField *)textField {
if (textField == self.txtFieldOne &&
[textField.text isEqualToString:@"done"]) {
return NO;
}
return YES;
}
@interface ViewController : UIViewController <UITextViewDelegate, UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txtFieldOne;
@property (weak, nonatomic) IBOutlet UITextField *txtFieldTwo;
@property (weak, nonatomic) IBOutlet UITextView *txtView;
@property (weak, nonatomic) IBOutlet UIButton *btnButton;
- (IBAction)tappedButton:(id)sender;
@end
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == self.txtFieldOne) {
textField.text = @"Don't edit me!";
}
}
- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
if (textField == self.txtFieldTwo &&
[textField.text isEqualToString:@"No Change"]) {
return NO;
}
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment