我想为 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;