iOS_ UITextField相关代码

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


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

- (
void )textFieldDidEndEditing:( UITextField *)textField{
        [
self textFieldAnimate :textField isUp : NO ];
}

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

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


#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"]; 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值