Reputation: 4951
I have a UITextField set up in Interface Builder with a background image. The background shows up fine, but when I switch (in IB) the Class name to my UITextField subclass (ValidatedTextField), the background image doesn't show. Can anyone spot any reason why the image should not be there for my UITextView subclass?
Other info
Don't know if this helps but IB has also been giving me some trouble -- sometimes not allowing me to change the class name of these text fields..
//ValidatedTextField.h
#import <UIKit/UIKit.h>
#import "MBValidated.h"
@interface ValidatedTextField : UITextView <MBValidated>
// the maximum characters allowed
@property (assign, nonatomic) int mbMaxLength;
// an visual indicator of the validation state (checkmark, etc)
@property (strong, nonatomic) UIImageView *mbStatusImageView;
// whether the field can be empty
@property (assign, nonatomic) BOOL mbIsRequired;
// whether we have succesfully validated
@property (assign, nonatomic) BOOL mbIsValid;
// validate and update stored validated state
-(BOOL)mbValidate;
@end
// ValidatedTextField.m
#import "ValidatedTextField.h"
@implementation ValidatedTextField
@synthesize mbMaxLength, mbStatusImageView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// set any default values here
-(void)mbSetDefaults
{
self.mbIsRequired = YES;
self.mbIsValid = YES;
}
-(BOOL)mbValidate
{
// validate length
if(self.text.length > self.mbMaxLength) self.mbIsValid = NO;
// validate empty or filled
if(self.text.length == 0 && self.mbIsRequired == YES) self.mbIsValid = NO;
return self.mbIsValid;
}
- (void)awakeFromNib
{
// set defaults
[self mbSetDefaults];
}
@end
// MBValidated Protocol
#import <Foundation/Foundation.h>
@protocol MBValidated <NSObject>
// whether the field can be empty
@property (assign, nonatomic) BOOL mbIsRequired;
// whether we have succesfully validated
@property (assign, nonatomic) BOOL mbIsValid;
// validate the item
-(BOOL)mbValidate;
@end
Upvotes: 0
Views: 272