I inherits my "MFTextField" class from UITextField. I want to customize the frame of the "rightView" property of the UITextField with an IBInspectable property from Interface Builder. To do that :
IB_DESIGNABLE
@interface MFTextField : UITextField <UITextFieldDelegate, MFComponentValidationDelegate>
@property (nonatomic) IBInspectable CGRect errorViewFrame;
@end
And in my MFtextField.m :
-(CGRect)rightViewRectForBounds:(CGRect)bounds {
if(CGRectEqualToRect(CGRectZero, self.errorViewFrame)) {
//default position
CGRect rightViewRect = self.errorView.bounds;
rightViewRect.size.height = bounds.size.height - 4;
rightViewRect.origin.y = 2;
rightViewRect.origin.x = bounds.size.width - rightViewRect.size.width - 2;
return rightViewRect;
}
else {
//Custom position
return self.errorViewFrame;
}
}
I Declare my rightView :
self.errorView = [[[NSBundle bundleForClass:[self class]] loadNibNamed:@"MFErrorView" owner:nil options:nil] firstObject];
self.rightView = self.errorView;
self.rightView = UITextFieldViewModeAlways;
Okay. Now i see the my rightView with de default position on IB, and i'm allowed to customize its frame :
But when i want to change the value of my "Error view frame" IBinspectable property, XCode begins an infinite loop then crashes... It seems that the method rightViewRectForBounds: is infinitely called by iOS now...
Any idea ?