- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing. - (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder - (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end - (void)textFieldDidEndEditing:(UITextField *)textField; // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called - (void)textFieldDidEndEditing:(UITextField *)textFieldreason:(UITextFieldDidEndEditingReason)reasonNS_AVAILABLE_IOS(10_0); // if implemented, called in place of textFieldDidEndEditing:
- (BOOL)textField:(UITextField *)textFieldshouldChangeCharactersInRange:(NSRange)rangereplacementString:(NSString *)string; // return NO to not change text
- (BOOL)textFieldShouldClear:(UITextField *)textField; // called when clear button pressed. return NO to ignore (no notifications) - (BOOL)textFieldShouldReturn:(UITextField *)textField; // called when 'return' key pressed. return NO to ignore.
- (void)drawHypnoticMessage:(NSString *)message { for (int i = 0; i < 20; i++) { UILabel *messageLabel = [[UILabel alloc] init];
// Configure the label's colors and text messageLabel.backgroundColor = [UIColor clearColor]; messageLabel.textColor = [UIColor whiteColor]; messageLabel.text = message;
// This method resizes the label, which will be relative // to the text that it is displaying [messageLabel sizeToFit];
// Get a random x value that fits within the hypnosis view's width int width = self.view.bounds.size.width - messageLabel.bounds.size.width; int x = arc4random_uniform(width);
// Get a random y value that fits within the hypnosis view's height int height = self.view.bounds.size.height - messageLabel.bounds.size.height; int y = arc4random_uniform(height);
// Setting the border style on the text field will allow us to see it easier textField.borderStyle = UITextBorderStyleRoundedRect; textField.placeholder = @"Hypnotize me"; textField.returnKeyType = UIReturnKeyDone; [backgroundView addSubview:textField];
textField.delegate = self;
// Set it as *the* view of this view controller self.view = backgroundView; }
- (void)viewDidLoad { // Always call the super implementation of viewDidLoad [super viewDidLoad];
NSLog(@"BNRHypnosisViewController loaded its view"); }
- (void)drawHypnoticMessage:(NSString *)message { for (int i = 0; i < 20; i++) { UILabel *messageLabel = [[UILabel alloc] init];
// Configure the label's colors and text messageLabel.backgroundColor = [UIColor clearColor]; messageLabel.textColor = [UIColor whiteColor]; messageLabel.text = message;
// This method resizes the label, which will be relative // to the text that it is displaying [messageLabel sizeToFit];
// Get a random x value that fits within the hypnosis view's width int width = self.view.bounds.size.width - messageLabel.bounds.size.width; int x = arc4random_uniform(width);
// Get a random y value that fits within the hypnosis view's height int height = self.view.bounds.size.height - messageLabel.bounds.size.height; int y = arc4random_uniform(height);