Shaunak
Shaunak

Reputation: 717

Setting Custom UITextField

I want to create a custom UITextField like the one shown in image1 but I am only able to create the boxes like in image2. Can anybody help how to perform these in UITextField:

1) to set the starting of text after some space (see image1)

2) to set the corners to rounded rectangle shape (see image1)

Image1 Image2

Upvotes: 0

Views: 1259

Answers (4)

iPatel
iPatel

Reputation: 47049

first Add #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];

Another option is :

Add UITextField on UIImageView...take imageView as roundRect and put UITextField on imageView ,, size of UIImageView is big (not more) then uitextField and give uitextfield backgroung color clearColor...such like

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

Upvotes: 0

Trinstan
Trinstan

Reputation: 41

Don't use UITextview, use UITextField instead.

Then you can set the UITextBorderStyle as UITextBorderStyleNone, use the rounded rectangle shape image as the background.

Feel free to send me feedback

Upvotes: 0

vishnu
vishnu

Reputation: 239

Add Quartzcore framework to your project

import QuartzCore/QuartzCore.h

and use [YourtextView.layer setCornerRadius:2.0];

Hope this help you

Upvotes: 0

guenis
guenis

Reputation: 2538

Have a look at these 2 methods:

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

Upvotes: 1

Related Questions