设置自定义UITextField

时间:2013-02-04 09:03:08

标签: ios uitextview

我想创建一个自定义UITextField,就像在image1中显示的一样,但我只能创建像image2中的方框。任何人都可以帮助您在UITextField中执行这些操作:

1)在一些空格后设置文本的开头(见图1)

2)将角设置为圆角矩形(见图1)

Image1 Image2

4 个答案:

答案 0 :(得分:1)

看看这两种方法:

#import <QuartzCore/QuartzCore.h> //For accessing and modifying layer property of view

//Rounded corners
[textView.layer setCornerRadius:3.0];

//Putting left margin to the textview (set your desired margins)
[textView setContentInset:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];

答案 1 :(得分:0)

将Quartzcore框架添加到您的项目中

导入QuartzCore / QuartzCore.h

并使用[YourtextView.layer setCornerRadius:2.0];

希望这能帮到你

答案 2 :(得分:0)

不要使用UITextview,而是使用UITextField。

然后你可以将UITextBorderStyle设置为UITextBorderStyleNone,使用圆角矩形形状图像作为背景。

随时向我发送反馈

答案 3 :(得分:0)

首先添加#import <QuartzCore/QuartzCore.h>

UITextField *YourTextViewName = [[UITextField alloc] initWithFrame:CGRectMake(@"YourSize")];
YourTextViewName.delegate = self;
YourTextViewName.tag = 1;
[self.view addSubview:YourTextViewName];
YourTextViewName.backgroundColor = [UIColor whiteColor];

[[YourTextViewName layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
[[YourTextViewName layer] setBorderWidth:1.0];
[[YourTextViewName layer] setCornerRadius:10];

另一种选择是:

在UIImageView上添加UITextField ...将imageView作为roundRect并将UITextField放在imageView上,UIImageView的大小很大(不多于)然后uitextField并给出uitextfield背景颜色clearColor ...像

UIImageView *imgTxtTag = [[UIImageView alloc] initWithFrame:CGRectMake(25, 150, 265, 30)] ;
    [imgTxtTag setImage: [UIImage imageNamed:@"SurfaceBtnBG.png"]];
    [self.scrollView addSubview:imgTxtTag];

UITextField *YourTextViewName = [[UITextField alloc] initWithFrame:CGRectMake(@"33, 150, 249, 30")];
    YourTextViewName.delegate = self;
YourTextViewName.backgroundColor = [UIColor clearColor];
    YourTextViewName.tag = 1;
    [self.view addSubview:YourTextViewName];