iOS_ UITextField相关代码

来源:互联网 发布:mac中文输入法全角 编辑:程序博客网 时间:2024/05/18 22:50

我发这篇的初衷很简单, 就是我用到得时候直接copy的, 完全没有技术难点什么的


#pragma mark ----编辑不被遮挡
// textField上移动画
- (
void)textFieldAnimate:(UITextField*)textField isUp:(BOOL)isUp{
   
int movementDistance =140;
   
// 根据需要调整平移距离
   
float movementDuration = 0.3f;
   
int movement = (isUp ? -movementDistance : movementDistance);
    [
UIViewbeginAnimations:@"textFieldAnimation"context:nil];
    [
UIViewsetAnimationBeginsFromCurrentState:YES];
    [
UIViewsetAnimationDuration:movementDuration];
   
self.view.frame=CGRectOffset(self.view.frame,0, movement);
    [
UIViewcommitAnimations];
}
#pragma mark- TextField Delegate
- (void)textFieldDidBeginEditing:(UITextField*)textField{
    [
selftextFieldAnimate:textFieldisUp:YES];
}

- (
void)textFieldDidEndEditing:(UITextField*)textField{
        [
selftextFieldAnimate:textFieldisUp:NO];
}

#pragma mark ----键盘消失
- (void)resignKeyboard
{
    [
_communityTFresignFirstResponder];
}

-(
void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    [
_communityTFresignFirstResponder];
}


#pragma mark ----修改placeholder的字体颜色、大小

  1. textField.placeholder = @"username is in here!";  
  2. [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
  3. [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"]; 


0 0