iPhone UITextField和UIButton位于一个灰色框架中

iPhone UITextField和UIButton位于一个灰色框架中,iphone,ios5,uibutton,uitextfield,Iphone,Ios5,Uibutton,Uitextfield,我想创建如下内容: 我想把一个带有UIButton的UIExtField放在一个灰色框架中,我希望按钮的边框包含在这个灰色框架中 请有人给我看一些示例代码 谢谢 1.使用所需rect的UIImageView。将背景图像设置为渐变灰色图像 UIImageView*myImageView=[[UIImageView alloc] initWithFrame:yourFrame]; [myImageView setImage:[UIImage imageNamed:@"grayBackgroun

我想创建如下内容:

我想把一个带有UIButton的UIExtField放在一个灰色框架中,我希望按钮的边框包含在这个灰色框架中

请有人给我看一些示例代码


谢谢

1.使用所需rect的
UIImageView
。将背景图像设置为渐变灰色图像

 UIImageView*myImageView=[[UIImageView alloc] initWithFrame:yourFrame];
 [myImageView setImage:[UIImage imageNamed:@"grayBackground.png"];
 [self.view addSubview:myImageView];
2.使用圆形矩形
UITextField
将其作为图像视图的子视图。将占位符用作“编写答复…”使其成为imageview的子视图

UITextField*myField=[[UITextField alloc] initWithFrame:yourRect];
[myField setBorderStyle:UITextBorderStyleRoundedRect];
[myField setPlaceholder:@"Write a reply..."];
[myImageView addSubview:myField];
UIButton*myButton=[UIButton buttonWithType:UIButtonTypeCustom];
[myButton setFrame:yourRect]
[myButton setBackgroundImage:[UIImage imageNamed:@"sendImage.png"] forState:UIControlStateNormal];
[myImageView addSubView:myButton];
3.使用带有
Custom
类型的
ui按钮,将发送图像作为其背景图像,使其成为imageview的子视图

UITextField*myField=[[UITextField alloc] initWithFrame:yourRect];
[myField setBorderStyle:UITextBorderStyleRoundedRect];
[myField setPlaceholder:@"Write a reply..."];
[myImageView addSubview:myField];
UIButton*myButton=[UIButton buttonWithType:UIButtonTypeCustom];
[myButton setFrame:yourRect]
[myButton setBackgroundImage:[UIImage imageNamed:@"sendImage.png"] forState:UIControlStateNormal];
[myImageView addSubView:myButton];

简单的方法是创建带有灰色背景的标题栏并删除标题。然后放置文本字段和您想要放置的按钮。在标题栏外配置大小和按钮,并将其拖动到标题栏。您将获得与您获得的图像相似的图像


我曾尝试在IB中构建它,创建了一个UIView,并将另外两个视图放在上面,但我找不到好的属性。很抱歉,你不得不读我的问题…我之所以没有写这篇文章,是因为我不想尝试,或者我很懒,或者如果我使用其他人的代码对我来说更好。我写这篇文章是因为我不知道该怎么做,我想人们来寻求帮助的地方,将是一个好地方。。。