我有一个大小为 360X44 的背景图像,我试图将其作为我的 UITextFields 的背景,但是它显示出意外的行为。光标在图像开始之前出现,但文本在写入位置写入。
我的 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 背景图像并且工作正常:-
[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];
看起来像“-
关于iphone - 光标出现在自定义的 UITextField 背景图像之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14619097/