0
我是iOS新手。我想爲我的應用程序中的每個文本字段擴展UITextField類,以便每個UITextField都可以有一個底部邊框和一個鍵盤圖標。這可能看起來像下面的圖像。擴展UITextField類添加視圖
this is what I am trying it to look like
下面是我試過,但不知該子視圖不來在屏幕上
// InputField.h
@interface InputField : UITextField <UITextFieldDelegate>
@end
// InputField.m
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.delegate = self;
[self prepareTextField];
}
return self;
}
- (void)prepareTextField {
UIView *bottomLine = [[UIView alloc] init];
bottomLine.frame = CGRectMake(self.frame.origin.x,
-self.frame.size.height,
self.frame.size.width,
self.frame.size.height);
bottomLine.backgroundColor = [UIColor redColor];
[self addSubview:bottomLine];
}
您可以檢查材料設計庫中的類似效果。而對於右側的圖像,您可以使用文本字段的rightView屬性。讓我知道如果這有幫助... – Janmenjaya
但是,如果我在我的viewDidLoad做同樣的東西,它工作正常。所以我假設我的文本字段在時間代碼命中'InputField'時在視圖層次結構中不可用 – user3590346