我想为UITextField的inputView属性设置自定义视图。 (基本上是因为我想将UILabel添加到UIPickerView的selectionIndicator中,我找不到更简单的方法......)如果我将UIPickerView设置为inputView,一切都正常。但是如果我将UIView设置为inputView,那么当UITextField成为firstResponder时它就不会显示出来。有没有人在这里得到解释?
这有效:
UITextField* field = [[UITextField alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
// configuration of field
UIPickerView* pickerView = [[UIPickerView alloc] initWithFrame:field.inputView.frame];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
field.inputView = pickerView;
这不是:
UITextField* field = [[UITextField alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
// configuration of field
UIView* view = [[UIView alloc] initWithFrame:field.inputView.frame];
view.backgroundColor = [UIColor redColor];
field.inputView = view;