我想創建一個自定義UITextField
像圖像1所示的一個,但我只能夠創建盒子,像是圖像2。任何人可以幫助如何在UITextField
執行這些:設置自定義的UITextField
1)後一些空間文本的起點設置(見圖像1)
2)設置彎道圓角矩形(見圖像1)
我想創建一個自定義UITextField
像圖像1所示的一個,但我只能夠創建盒子,像是圖像2。任何人可以幫助如何在UITextField
執行這些:設置自定義的UITextField
1)後一些空間文本的起點設置(見圖像1)
2)設置彎道圓角矩形(見圖像1)
看一看這2種方法:
#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#>)];
添加Quartzcore框架到您的項目
進口QuartzCore/QuartzCore.h
,並使用[YourtextView.layer setCornerRadius:2.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];
另一種選擇是:
添加的UITextField上的UIImageView ......採取的ImageView爲ROUNDRECT放的UITextField上的ImageView ,,的UIImageView的大小大(甚至更多),然後的UITextField,給的UITextField backgroung顏色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];
只是快速筆記。爲了使用'textView.layer',你必須首先在文件中執行'#import'。 –
Fogmeister
哦,你是對的@fogmeister,我會編輯代碼 – guenis
setCornerRadius是工作,但setContentInset不工作,因爲它不提供的UITextField ... – Shaunak