UITextField調整樣式時注意事項

當對UITextField進行樣式調整時,最好不要用textFieldShouldBeginEditing和textFieldShouldReturn,

用以下方法來替代

// 當輸入框獲得焦點時,執行該方法。
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    textField.layer.borderWidth = 1;
    textField.layer.borderColor = [[UIColor greenColor] CGColor];
    
}

// 文本框失去first responder 時,執行
- (void)textFieldDidEndEditing:(UITextField *)textField{
    textField.layer.borderWidth = 1;
    textField.layer.borderColor = [[UIColor clearColor] CGColor];
    
}

原因是有些第三方彈出鍵盤控制模塊會多次調用textFieldShouldBeginEditing事件導致不符合預期的結果出現,textFieldShouldBeginEditing和textFieldShouldReturn通常是拿來做鍵盤的彈出控制。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章