简体   繁体   中英

How to remove default border of UITextView

Hi I want to remove Default gray border of tHe View. so by doing this we can not find the textview on view. How we can do this?

If you use this it will change the border style to the way your describe. You say TextView, though do you mean the textField? The text field can have a default grey rounded border. To remove do this.

textField.borderStyle = UITextBorderStyleNone;

where the 'textField' is the name of your textfield.

If you visit this link to Apple's documentation on the textField's properties I'm sure it will help with any other things you want to change. If it is the TextView field you meant, then the apple documentation will give you properties to use here too.

Hope this help, cheers, Jim.

[textView.layer setBorderWidth:0.0f];

The best way I think, 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 have to add to your project: #import <QuartzCore/QuartzCore.h> framework

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

The remember this issue way back when working with multiple text views. The best solution I can come up with is this:

MyTextView.h


@interface MyTextView : UITextView

@end

MyTextView.m



#import "MyTextView.h"

@implementation MyTextView

 - (void)drawRect:(CGRect)rect
{
    self.layer.borderWidth = 0.0f;
}

@end

迅捷5

textView.layer.borderWidth = 0

If you want to do this from the storyboard, you can select make the appropriate selection under border style (located at the bottom of the image). Click on the text field, go to Attributes -> Border Style and the dotted option removes the border.

在此处输入图片说明

斯威夫特 3

textView.borderStyle = .none

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM