如何使用borderwidth和borderColor制作半圆形(顶角圆角)textview或tableview?
答案 0 :(得分:2)
这并不完美,但你可以从中做到:
#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];
答案 1 :(得分:1)
首先删除所有会生成边框的代码(xib或layer.borderWidth),并使用下面我在UIView类别中创建的方法:
#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
答案 2 :(得分:0)
我认为使用以下代码
[yourTextView.layer setBorderColor: [[UIColor redColor] CGColor]];
[yourTextView.layer setBorderWidth: 1.0];
[yourTextView.layer setCornerRadius:8.0f];
[yourTextView.layer setMasksToBounds:YES];
也使用TableView而不是TextView