【问题标题】:UITextfield cursor movesUITextfield 光标移动
【发布时间】:2016-07-15 10:50:48
【问题描述】:

我试图在文本更改时动态更改 UITextField 字体大小。 但是当我这样做时,我的文本字段光标会向上移动。 因此,如果有人知道解决方案,请提供帮助。

请查看图片以供参考。 谢谢。

-(void)textChanged:(id)sender{

    UITextField *textFild = (UITextField*)sender;
    if ([textFild.text isEqualToString:@""]) {
        [textFild setFont:FONT_30];
    }
    else{
        [textFild setFont:FONT_15];
    }
    textFild.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}

请检查代码..

【问题讨论】:

    标签: ios objective-c uitextfield


    【解决方案1】:

    动态设置字体大小后添加此行。这对你有用。

    txtFieldPassword.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    

    而不是txtFieldPasswordIBOutlet 您各自textfield 的名称。

    【讨论】:

    • 您能否在此处添加一些有关将字体设置为文本字段的代码。
    【解决方案2】:

    这是预期的行为。设置文本字段的文本以及字体。因此光标将重置为正常位置。

    -(void)textChanged:(id)sender {
        UITextField *textFild = (UITextField*)sender;
        NSString *tmpString = textFild.text; 
        if ([textFild.text isEqualToString:@""]) {
            textFild.text=tmpString;
            [textFild setFont:FONT_30];
        } else {
             textFild.text=tempString;
            [textFild setFont:FONT_15];
        }
        textFild.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 2011-03-10
      • 1970-01-01
      • 2019-11-19
      • 2012-06-24
      • 1970-01-01
      相关资源
      最近更新 更多