如何制作一个半边圆angular(顶angular圆angular)texview带边框?

如何使用borderwidth和borderColor来制作半angular圆angular(顶angular圆angular)textview或tableview? 在这里输入图像说明

这不是完美的,但你可以从这个工作:

 #import <QuartzCore/CoreAnimation.h> 

(也链接到你的项目中的QuartzCore.framework),然后..

 self.textView.layer.borderColor = [UIColor redColor].CGColor; self.textView.layer.borderWidth = 4.0f; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.textView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(7.0, 7.0)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.textView.bounds; maskLayer.path = maskPath.CGPath; self.textView.layer.mask = maskLayer; [maskLayer release]; 

首先删除所有将生成边界(xib或layer.borderWidth)的代码,并使用下面我在UIView类中创build的方法:

 #import "UIView+RoundedCorners.h" @implementation UIView (RoundedCorners) #pragma mark - Public - (void)addBorderWithRoundedCorners:(UIRectCorner)roundedCorners radius:(CGFloat)radius color:(UIColor *)color { self.clipsToBounds = NO; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:roundedCorners cornerRadii:CGSizeMake(radius, radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = self.bounds; maskLayer.path = maskPath.CGPath; maskLayer.lineWidth = 1.0; maskLayer.strokeColor = color.CGColor; maskLayer.fillColor = [UIColor clearColor].CGColor; [self.layer addSublayer:maskLayer]; } @end 

我想用波纹pipe的代码

  [yourTextView.layer setBorderColor: [[UIColor redColor] CGColor]]; [yourTextView.layer setBorderWidth: 1.0]; [yourTextView.layer setCornerRadius:8.0f]; [yourTextView.layer setMasksToBounds:YES]; 

也使用yourTableView insted你的TextView