How to remove default border UITextView

Hi, I want to remove the default gray border of tHe View. therefore, by doing this, we cannot find the textual representation in sight. How can we do this?

+11
ios border uitextview
source share
5 answers

If you use this, it will change the frame style to the way you describe. You say TextView, although you mean textField? The text box may have a gray rounded image by default. To remove this,

textField.borderStyle = UITextBorderStyleNone; 

where "textField" is the name of your text field.

If you visit this link in the Apple documentation in the textField properties, I am sure this will help with any other things that you want change. If this is the TextView field that you had in mind, then the apple documentation will provide you with properties that you can use here.

Hope this help, greetings, Jim.

+12
source share

[textView.layer setBorderWidth: 0.0f];

+11
source share

The best way, I think, is to subclass UITextView and override the drawRect method, for example:

.h

 #import <UIKit/UIKit.h> @interface CustomTextView : UITextView @end 

.m

 #import "CustomTextView.h" #import <QuartzCore/QuartzCore.h> @implementation CustomTextView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { // Drawing code self.backgroundColor = [UIColor whiteColor]; self.layer.cornerRadius = 5; // plus info: you can add any border what you want self.layer.borderColor = [UIColor blueColor].CGColor; self.layer.borderWidth = 2.0; } @end 

if you want to use self.layer ... you should add to your project: #import <QuartzCore/QuartzCore.h> framework

In this method, you can make any style you want.

+1
source share

Remember this problem again when working with multiple text views. The best solution I can come up with is the following:

MyTextView.h

 @interface MyTextView : UITextView @end
@interface MyTextView : UITextView @end 

MyTextView.m

 #import "MyTextView.h" @implementation MyTextView - (void)drawRect:(CGRect)rect { self.layer.borderWidth = 0.0f; } @end
#import "MyTextView.h" @implementation MyTextView - (void)drawRect:(CGRect)rect { self.layer.borderWidth = 0.0f; } @end 
+1
source share

Swift 3

 textView.borderStyle = .none 
-2
source share

All Articles