2012-01-08 72 views
3

我想周圍添加邊框的UITextView使用邊框沒有顯示出來

self.textView.layer.borderWidth = 1; 

    self.textView.layer.borderColor = [[UIColor brownColor] CGColor]; 

,但它沒有顯示出來。如果任何人都可以幫助我,爲什麼它不顯示。儘管我已經添加了Quartz框架。但仍然沒有出現。

#import "uitextviewViewController.h" 
#import <QuartzCore/QuartzCore.h> 


@implementation uitextviewViewController 

@synthesize textView; 
@synthesize navBar; 


- (void)dealloc { 

[navBar release]; 
    [textView release]; 

[super dealloc]; 
} 


- (void) viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIBarButtonItem * button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                     target:self 
                     action:@selector(done:)]; 
[[self navigationItem] setRightBarButtonItem:button]; 
[button release]; 

self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease]; 

self.textView.textColor = [UIColor whiteColor]; 

self.textView.font = [UIFont fontWithName:@"Arial" size:15]; 

self.textView.delegate = self; 

self.textView.backgroundColor = [UIColor brownColor]; 

self.textView.layer.borderWidth = 1; 

self.textView.layer.borderColor = [[UIColor brownColor] CGColor]; 

self.textView.textAlignment = UITextAlignmentCenter; 

self.textView.text = @"This is UITextView\n\nThis is UITextView\n\nThis is UITextView\n\nThis is UITextView\n\nThis is UITextView."; 

self.textView.scrollEnabled = YES; 
[self.view addSubview: self.textView]; 

} 

我將不勝感激。

在此先感謝。

+0

可能重複[如何風格的UITextView喜歡圓角的矩形文本字段?](http://stackoverflow.com/questions/1824463/how-to-style-uitextview-to-like-rounded-rect-text-field) – Steve 2012-01-10 20:31:14

回答

2

在這裏,使用這個。

修改它,只要你願意。

UITextFieldWrapper.h

#import <UIKit/UIKit.h> 

@interface UITextFieldWrapper : UIView 

@property (nonatomic, weak, readonly) UITextField * textField; 

@end 

UITextFieldWrapper.m

#import "UITextFieldWrapper.h" 
#import <QuartzCore/QuartzCore.h> 

@implementation UITextFieldWrapper 

@synthesize textField = _textField; 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
     self.layer.borderWidth = 1.0; 
     self.layer.borderColor = [[UIColor blackColor] CGColor]; 
     self.backgroundColor = [UIColor whiteColor]; 
     self.clipsToBounds = YES; 

     UITextField * textField = [[UITextField alloc] initWithFrame:CGRectMake(3, 3, frame.size.width - 6, 21)]; 
     textField.backgroundColor = [UIColor whiteColor]; 
     [self addSubview:textField]; 
     _textField = textField; 
    } 
    return self; 
} 

@end 
+0

我將邊框顏色從棕色變爲現在顯示的白色。但仍然邊界顯示只有三面牆沒有顯示底部第四面牆。任何想法丟失 – user1120133 2012-01-08 22:27:37

+0

框架太大或太小。嘗試27高度。 – Steve 2012-01-08 22:31:15

+0

@ user1120133,如果你喜歡我的回答,你會如此友善,以便將其標記爲「已接受」?謝謝! – Steve 2012-01-08 23:02:57

4

下面的代碼是使用了給UITextbox或其他控制器爲的圓弧您需要使用#import frame work,那麼你可以使用下面的代碼來控制邊界或弧形。

imgThumb.layer.cornerRadius = 5; 
imgThumb.layer.masksToBounds = YES; 
imgThumb.layer.borderColor = [UIColor grayColor].CGColor; 
imgThumb.layer.borderWidth = 0.9; 

如果對此有任何疑問,請在這裏評論... 編碼愉快的

+0

仍然我無法看到邊框的底部,並且無法滾動eventhough滾動在我的代碼中啓用。 – user1120133 2012-01-09 16:34:12

+0

其實UITextView支持編輯的內容,而不是我想要的內容。所以我認爲uiscrollview將解決我的目的。讓我試試看。 – user1120133 2012-01-09 16:44:33