0
我有一個UITextField在界面生成器中設置了背景圖片。後臺顯示正常,但是當我將Class名稱切換(在IB中)到我的UITextField子類(ValidatedTextField)時,背景圖像不顯示。任何人都可以找到爲什麼圖像不應該在我的UITextView子類的任何原因?爲什麼UITextField子類背景圖像不顯示?
其他信息
不知道這是否幫助,但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
Duh ...該死的自動完成!謝啦。很好的接收 – sean 2013-03-06 00:20:50