Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将UITextField添加到UIImageView布局问题_Iphone_Objective C_Uiimageview_Uitextfield - Fatal编程技术网

Iphone 将UITextField添加到UIImageView布局问题

Iphone 将UITextField添加到UIImageView布局问题,iphone,objective-c,uiimageview,uitextfield,Iphone,Objective C,Uiimageview,Uitextfield,可能重复: 我有一个UIImageView(图像中有图案、渐变和阴影)。我已经添加了一个UIExtField作为这个UIImageView的子视图,并将textField背景设置为clear,以便可以看到它,代码是: UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 12, 359 , 36)]; textField.autocorrectionType = UITextAutocorre

可能重复:

我有一个UIImageView(图像中有图案、渐变和阴影)。我已经添加了一个UIExtField作为这个UIImageView的子视图,并将textField背景设置为clear,以便可以看到它,代码是:

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"]];
然而,我得到的是:


将UITextField作为子视图添加到viewcontroller的视图中,而不是“用户名\背景”UIImageView。我相信这会解决你的问题。

试着制作一张新图像,用作背景,只包含原始图像中心的图案(没有渐变或角点)

我知道这会解决它,但我正在寻找一种不同的方法,实际上它不会,它不会解决如上所示的复制和粘贴问题。。它仍然有白色的文本空间,你可以发布你用来构建这个视图的代码吗?