光标出现在自定义的UITextField背景图像之前 [英] Cursor appears before customized UITextField background image

查看:33
本文介绍了光标出现在自定义的UITextField背景图像之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个尺寸为360X44的背景图像,尝试将其作为UITextFields的背景,但是它显示了意外的行为.在图像开始之前光标就出现了,但是文本被写在了书写位置上.

I have a background image of size 360X44 which I am trying to put as the background of my UITextFields however it is showing an unexpected behaviour. The cursor is getting appeared before the image starts but the texts getting written on the write place.

UiTextField的实现

UITextField *textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(100, 75, 215, 30)];
textFieldRounded.borderStyle = UITextBorderStyleNone;
UIImage *fieldBGImage = [[UIImage imageNamed:@"textfield_normal.png"]  stretchableImageWithLeftCapWidth:50 topCapHeight:50];
[textFieldRounded setBackground:fieldBGImage];
textFieldRounded.textColor = [UIColor blackColor];
textFieldRounded.font = [UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder = @"http://";  //place holder
textFieldRounded.backgroundColor = [UIColor whiteColor];
textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo;
textFieldRounded.backgroundColor = [UIColor clearColor];
textFieldRounded.keyboardType = UIKeyboardTypeDefault;
textFieldRounded.returnKeyType = UIReturnKeyDone;
textFieldRounded.clearsOnBeginEditing = NO;
textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing;    
[self.view addSubview:textFieldRounded];    
textFieldRounded.delegate = self;

推荐答案

我只是将TextFiled背景图像设置为像我的波纹管代码一样,并且工作良好:-

i just set TextFiled background Image like my bellow code And working Good:-

        [YourTextFiled setFont:[UIFont systemFontOfSize:18]];
        YourTextFiled.textAlignment = UITextAlignmentLeft;
        YourTextFiled.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
        YourTextFiled.leftViewMode = UITextFieldViewModeAlways;
        YourTextFiled.background = [[UIImage imageNamed:@"xFOEr.png"] stretchableImageWithLeftCapWidth:7 topCapHeight:17];

看起来像-

这篇关于光标出现在自定义的UITextField背景图像之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆