开发者

custom UITextField with image as a background blinking cursor issue

I have a custom UITextField with a UIImage as a background. Now when I type in a text into this UITextField and the cursor is blinking I get this:

custom UITextField with image as a background blinking cursor issue

I don't want to have a white image on the cursor blinking as it destroys the aesthetics. I tried playing around with this and tried setting the background view to have the same color as the image, however the issue is that the UITextField shape is always a rectangle. How do I solve this?开发者_JAVA百科


Have you tried setting textField.backgroundColor = [UIColor clearColor]?

You can use a UIImageView for the image and then add a UITextField as a subview with clear background. Just create UIImageView *imageView and UITextField *textField, either programmatically or in the IB. If you go programmatically, use [imageView addSubview:textField]; and set the frame as you like. In the IB, just drop the textField onto the imageView and align it as you like.


I just tried it. It does not have the cursor highlighted like that.

set

textField.backgroundColor = [UIColor brownColor] // or your color

and

textField.textColor = [UIColor whiteColor];

For adding the textField into the 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];


What about creating a UIImageView with your image in it, and then embedding a borderless UITextField inside your image view? The text field will still be editable, but shouldn't interfere with the imageview behind it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜