簡體   English   中英

如何刪除 UITextView 的默認邊框

[英]How to remove default border of UITextView

嗨,我想刪除視圖的默認灰色邊框。 因此,通過這樣做,我們無法在視圖中找到 textview。 我們怎樣才能做到這一點?

如果您使用它,它會將邊框樣式更改為您描述的方式。 您說的是 TextView,但您是指 textField 嗎? 文本字段可以有一個默認的灰色圓形邊框。 要刪除執行此操作。

textField.borderStyle = UITextBorderStyleNone;

其中“textField”是您的文本字段的名稱。

如果您訪問 Apple 關於 textField 屬性的文檔的鏈接,我相信它會對您想要更改的任何其他內容有所幫助。 如果它是您指的 TextView 字段,那么蘋果文檔也會為您提供在這里使用的屬性。

希望這會有所幫助,加油,吉姆。

[textView.layer setBorderWidth:0.0f];

我認為最好的方法是繼承 UITextView 並覆蓋 drawRect 方法,例如:

.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

如果你想使用 self.layer.... 你必須添加到你的項目中: #import <QuartzCore/QuartzCore.h>框架

在這種方法中,您可以制作任何您想要的樣式。

在使用多個文本視圖時記住這個問題。 我能想出的最佳解決方案是:

文本視圖.h


@interface MyTextView : UITextView

@end

文本視圖.m



#import "MyTextView.h"

@implementation MyTextView

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

@end

迅捷5

textView.layer.borderWidth = 0

如果您想從情節提要中執行此操作,您可以選擇在邊框樣式(位於圖像底部)下進行適當的選擇。 單擊文本字段,轉到屬性 -> 邊框樣式,虛線選項將刪除邊框。

在此處輸入圖片說明

斯威夫特 3

textView.borderStyle = .none

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM