2010-10-13 59 views

回答

20

拳頭導入文件

#import <QuartzCore/QuartzCore.h> 

,然後設置文本視圖

yourTextViewName.layer.cornerRadius = kCornerRadius; 

的財產,其中kCornerRadius是你設置爲拐角

半徑
+0

感謝好友,....工作.. :) – 2010-10-13 12:13:34

+0

感謝它有幫助 – 2011-03-08 10:20:05

+0

我已經有一個錯誤「使用未聲明的標識符kCornerRadius」 – 2016-10-28 09:57:33

5

試試這個是一個常數將肯定工作

你必須導入

QuartzCore/QuartzCore.h 


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

我在.H定義一個類別類的UITextView:

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

和實現類:

#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 

實施例使用它:

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

這個問題被張貼很長一段時間回來.. :) – 2012-04-27 05:59:01