开发者

how to stretch a UITextField on begin editng

i want to increase the size 开发者_开发百科of UITextField when editing begins, but just cant get the code to do it.


Gomathi is correct. Just to add to his answer if you want the textFIeld to expand when editing begins and shrink back again when editing ends and also want to animate it, you might wanna do something like this:

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    [UIView animateWithDuration:0.5 animations:^{
        textField.frame = CGRectMake(textField.frame.origin.x-20, textField.frame.origin.y, textField.frame.size.width+40, textField.frame.size.height);
    }];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [UIView animateWithDuration:0.5 animations:^{
        textField.frame = CGRectMake(textField.frame.origin.x+20, textField.frame.origin.y, textField.frame.size.width-40, textField.frame.size.height);
    }];
    [textField resignFirstResponder];
    return YES;
}


Implement UITextFieldDelegate.

In - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField, set the new frame size to the textfield. Then call, [textField setNeedsDisplay];.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜