Fügen Sie ein Minus als accesoryView hinzu, Sie müssen Ihr textField als Eigenschaft haben, in diesem Beispiel ist diese Eigenschaft: myTextField;
Sie müssen hinzufügen, nach dem Erstellen Ihrer myTextField diesen Code, B.E. in viewDidLoad:
UIView *inputAccesoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
// It´s good idea a view under the button in order to change the color...more custom option
inputAccesoryView.backgroundColor = [UIColor whiteColor];
UIButton *minusButton = [[UIButton alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width-150)/2, 5, 150, 30)];
// configure the button here... you choose.
[minusButton setTitle:@"-" forState:UIControlStateNormal];
[minusButton addTarget:self action:@selector(changeNumberSing) forControlEvents:UIControlEventTouchUpInside];
[inputAccesoryView addSubview:minusButton];
self.myTextField.inputAccessoryView = inputAccesoryView;
und die Methoden dieser Schaltfläche in Ihrem Viewcontroller hinzu:
-(void)changeNumberSing
{
if ([self.myTextField.text hasPrefix:@"-"])
{
self.myTextField.text = [self.myTextField.text substringFromIndex:1];
}else
{
self.myTextField.text = [NSString stringWithFormat:@"-%@",self.myTextField.text];
}
}
erstellen Sie Ihre individuelle Tastatur – Sport
Andere Option, fügen Sie ein (-) Minus-Taste als eine inputAccessoryView. Oder seid glücklich mit: UIKeyboardTypeNumbersAndPunctuation –
@OnikIV Wie füge ich eine Minus-Schaltfläche als InputAccessoryView hinzu? – AndyW