开发者

adding UITextField to UIImageView layout issue [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

custom UITextField with image as a background blinking cursor issue

I have a UIImageView (the image has a pattern, gradient, and shadow in it). I have added a UITextField as a subview of this UIImageView and set the textField background to clear so that it's seen through, the code is:

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 12, 359 , 36)];
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.textColor = [UIColor whiteColor];
    textField.placeholder = @"USERNAME";
    textField.backgroundColor = [UIColor clearColor];
    textField.font = [UIFont systemFontOfSize:15];
    textField.delegate = self;
    [username_background addSubview:textField];

The issue is that when I start editing the UITextField, I got the following layout issues:

Before editing:

adding UITextField to UIImageView layout issue [duplicate]

When editing:

adding UITextField to UIImageView layout issue [duplicate]

adding UITextField to UIImageView layout issue [duplicate]

I can fix 开发者_运维知识库this if I change the UIColor clearColor background to some other color, but apparently I find difficulties getting the appropriate color for the background. I did try doing:

 [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bkg-username.png"]];

However, what I am getting is:

adding UITextField to UIImageView layout issue [duplicate]


Add the UITextField as a subview on the view of the viewcontroller, and not the 'username_background' UIImageView. I believe this should fix your problem.


Try making a new image to use as the background that consists of only the pattern in the center of the original image (no gradients or corners).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜