custom UITextField with image as a background blinking cursor issue

后端 未结 3 466

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:

相关标签:
3条回答
  • 2021-01-24 14:58

    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 讨论(0)
  • 2021-01-24 15:16

    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.

    0 讨论(0)
  • 2021-01-24 15:18

    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];
    
    0 讨论(0)
提交回复
热议问题