I created a subclass of UITextField to override the method rightViewRectForBounds.
Here is my custom class CustomTextField
@interface CustomTextField : UITextField
@end
@implementation CustomTextField
// override rightViewRectForBounds method:
- (CGRect)rightViewRectForBounds:(CGRect)bounds{
NSLog(@"rightViewRectForBounds");
CGRect rightBounds = CGRectMake(bounds.origin.x + 10, 0, 30, 44);
return rightBounds ;
}
@end
Now I set up my ViewController to call the custom class instead of UITextField.
#import "OutputViewController.h"
#import "CustomTextField.h"
@interface OutputViewController () <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet CustomTextField *field1;
@property (strong, nonatomic) IBOutlet UILabel *label1;
- (void)methodName
{
self.field1.rightView = self.label1;
}
The property rightView should call my method override according to Apple's Documentation: "The right overlay view is placed in the rectangle returned by the rightViewRectForBounds: method of the receiver". Why isn't my override working?
Sorry if this is a bad question. I've only been programming for a month.