2013年9月5日 星期四

UITextField 後面加入小x 清除 輸入 資料 / 清除的事件

step1.


 UITextField *endTextField;


endTextField[[UITextField alloc] initWithFrame:CGRectMake(10, 50, 300, 30)];

    [contentBaseView addSubview:endTextField];

endTextField.delegate = self;
    
endTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    
//加入後面的小xx
endTextField.clearButtonMode = UITextFieldViewModeWhileEditing;

step2.

//這是textfield 清除的事件

-(BOOL)textFieldShouldClear:(UITextField *)textField
{
    //NSLog(@"check in textFieldShouldClear");
    textField.text = @"";
    self.period.endDate = nil;
    return YES;
}

0 意見:

張貼留言