【发布时间】:2011-09-08 02:43:41
【问题描述】:
我有一个以 UIImage 作为背景的自定义 UITextField。现在,当我在这个 UITextField 中输入文本并且光标闪烁时,我得到了这个:
我不想让光标上的白色图像闪烁,因为它破坏了美感。 我尝试使用它并尝试将背景视图设置为与图像具有相同的颜色,但问题是 UITextField 形状始终是矩形。我该如何解决这个问题?
【问题讨论】:
标签: iphone objective-c ipad uitextfield
我有一个以 UIImage 作为背景的自定义 UITextField。现在,当我在这个 UITextField 中输入文本并且光标闪烁时,我得到了这个:
我不想让光标上的白色图像闪烁,因为它破坏了美感。 我尝试使用它并尝试将背景视图设置为与图像具有相同的颜色,但问题是 UITextField 形状始终是矩形。我该如何解决这个问题?
【问题讨论】:
标签: iphone objective-c ipad uitextfield
你试过设置textField.backgroundColor = [UIColor clearColor]吗?
您可以为图像使用 UIImageView,然后添加 UITextField 作为具有清晰背景的子视图。只需以编程方式或在 IB 中创建 UIImageView *imageView 和 UITextField *textField。如果您以编程方式进行,请使用[imageView addSubview:textField]; 并根据需要设置框架。在 IB 中,只需将 textField 放到 imageView 上,然后随意对齐即可。
【讨论】:
我刚试过。它没有像那样突出显示光标。
设置
textField.backgroundColor = [UIColor brownColor] // or your color
和
textField.textColor = [UIColor whiteColor];
用于将 textField 添加到 UIView ;
//Do this where you create the UIView* view
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.clearsOnBeginEditing = NO;
textField.textAlignment = UITextAlignmentRight;
textField.returnKeyType = UIReturnKeyDone;
textField.textColor = [UIColor blackColor]; // or any other color
textField.font = [UIFont systemFontOfSize:15];
textField.delegate = self;
[view addSubview:textField];
【讨论】:
如何创建一个包含您的图像的UIImageView,然后在您的图像视图中嵌入一个无边界的UITextField?文本字段仍可编辑,但不应干扰其后面的图像视图。
【讨论】: