如何使一个半圆角(上角四舍五入)与边境texview?(How to make a half rou

2019-09-18 00:42发布

如何使一个半圆角(上角四舍五入)的TextView或tableview中与边框宽度和边框颜色?

Answer 1:

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

#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];


Answer 2:

首先删除所有代码,将产生一个边界(厦门国际银行或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


Answer 3:

我想用波纹管代码

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

还使用yourTableView insted的yourTextView的



文章来源: How to make a half rounded (Top corner rounded) texview with border?