2013-02-04 128 views
0

我想創建一個自定義UITextField像圖像1所示的一個,但我只能夠創建盒子,像是圖像2。任何人可以幫助如何在UITextField執行這些:設置自定義的UITextField

1)後一些空間文本的起點設置(見圖像1)

2)設置彎道圓角矩形(見圖像1)

Image1 Image2

回答

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#>)]; 
+1

只是快速筆記。爲了使用'textView.layer',你必須首先在文件中執行'#import '。 – Fogmeister

+0

哦,你是對的@fogmeister,我會編輯代碼 – guenis

+0

setCornerRadius是工作,但setContentInset不工作,因爲它不提供的UITextField ... – Shaunak

0

添加Quartzcore框架到您的項目

進口QuartzCore/QuartzCore.h

,並使用[YourtextView.layer setCornerRadius:2.0];

希望這有助於你

0

不要使用UITextView的,使用的UITextField代替。

然後可以設置UITextBorderStyle作爲UITextBorderStyleNone,使用圓角矩形形狀圖像作爲背景。

隨時給我反饋

+0

對不起,我的意思的UITextField只..在編輯現在的問題.. – Shaunak

+0

偉大的...希望它運作良好 – Trinstan

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

我曾經使用UITextfield ..你可以給uitextfield內的手動位置輸入的答案? – Shaunak

+0

將其更改爲UTTextField – iPatel

+0

@Shaunak - 檢查我編輯的答案 – iPatel