2010-10-13 40 views

Trả lời

20

nắm tay nhập khẩu các tập tin

#import <QuartzCore/QuartzCore.h> 

và sau đó thiết lập các thuộc tính của quan điểm văn bản của bạn

yourTextViewName.layer.cornerRadius = kCornerRadius; 

nơi kCornerRadius là một hằng số bạn thiết lập như là một bán kính góc

+0

nhờ bạn thân , .... đã làm việc .. :) –

+0

cảm ơn nó giúp –

+0

Tôi đã có lỗi "sử dụng số nhận dạng không khai báo kCornerRadius" –

5

Thử này sẽ hoạt động chắc chắn

bạn phải nhập

QuartzCore/QuartzCore.h 


UITextView* txtView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 300, 100)]; 
txtView.layer.cornerRadius = 5.0; 
txtView.clipsToBounds = YES; 
1

tôi xác định một lớp loại cho UITextView trong .h:

@interface UITextView (RoundedCorner) 
-(void) roundedCornerDefault; 
-(void) roundedCornerWithRadius:(CGFloat) radius 
       borderColor:(CGColorRef) color 
       borderWidth:(CGFloat) width; 
@end 

và lớp thực hiện:

#import <QuartzCore/QuartzCore.h> 
#import "UITextView+RoundedCorner.h" 

@implementation UITextView (RoundedCorner) 

-(void) roundedCornerDefault { 
    [self roundedCornerWithRadius:10 
         borderColor:[[UIColor grayColor] CGColor] 
         borderWidth:1]; 
} 

-(void) roundedCornerWithRadius:(CGFloat) radius 
        borderColor:(CGColorRef) color 
        borderWidth:(CGFloat) width { 
    self.layer.cornerRadius = radius; 
self.layer.borderColor = color; 
self.layer.borderWidth = width; 
self.clipsToBounds = YES; 
} 
@end 

Ví dụ sử dụng:

#import "UITextView+RoundedCorner.h" 
... 
[self.myTextView roundedCornerDefault]; 
+0

Câu hỏi này đã được đăng một thời gian dài trở lại .. :) –