我在 Interface Builder 中设置了一个带有背景图像的 UITextField。背景显示得很好,但是当我(在 IB 中)将类名切换到我的 UITextField 子类(ValidatedTextField)时,背景图像不显示。谁能发现我的 UITextView 子类不应该有图像的任何原因?
其他信息
不知道这是否有帮助,但 IB 也给我带来了一些麻烦——有时不允许我更改这些文本字段的类名。
//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