【问题标题】:adding UITextField to UIImageView layout issue [duplicate]将 UITextField 添加到 UIImageView 布局问题 [重复]
【发布时间】:2011-06-03 21:58:40
【问题描述】:

可能重复:
custom UITextField with image as a background blinking cursor issue

我有一个 UIImageView(图像中有图案、渐变和阴影)。我添加了一个 UITextField 作为这个 UIImageView 的子视图,并将 textField 背景设置为清除,以便它被看穿,代码是:

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];

问题是当我开始编辑 UITextField 时,我遇到了以下布局问题:

编辑前:

编辑时:

如果我将 UIColor clearColor 背景更改为其他颜色,我可以解决此问题,但显然我发现很难为背景获取合适的颜色。我确实尝试过:

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

但是,我得到的是:

【问题讨论】:

    标签: iphone objective-c uiimageview uitextfield


    【解决方案1】:

    将 UITextField 添加为 viewcontroller 视图的子视图,而不是 'username_background' UIImageView。我相信这应该可以解决您的问题。

    【讨论】:

    • 你能发布你用来构建这个视图的代码吗?
    【解决方案2】:

    尝试制作仅由原始图像中心的图案组成的新图像用作背景(没有渐变或角落)。

    【讨论】:

    • 我知道这会解决它,但我正在寻找与此不同的方法
    • 其实不会,解决不了如上图的复制粘贴问题..还是有那个空白的文字空间
    猜你喜欢
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    相关资源
    最近更新 更多