BubbleLayer icon indicating copy to clipboard operation
BubbleLayer copied to clipboard

How to add borderColor and borderWidth?

Open dongchuanlei opened this issue 7 years ago • 3 comments

How to add borderColor and borderWidth?

dongchuanlei avatar May 04 '18 09:05 dongchuanlei

I'm so sorry I have no idea how to do it now, maybe I would implement it in a later version.

iHandle avatar May 16 '18 13:05 iHandle

I'm so sorry I have no idea how to do it now, maybe I would implement it in a later version.

Hello owner :

I add this function for you.

Firstly,add a UIColor property named strokeColor and a CGFloat property named lineWidth in BubbleLayer.h file.

// 路径颜色
@property (nonatomic, strong) UIColor *strokeColor;
// 路径宽度
@property (nonatomic, assign) CGFloat lineWidth;

Secondly, modify the code in BubbleLayer.m file.

Specific modification as follows:


// 生成用于mask的layer
- (CAShapeLayer *) layer {
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = [self bubblePath];
    if (_fillColor) {
        layer.fillColor = _fillColor.CGColor;
        if (_strokeColor) {
            layer.strokeColor = _strokeColor.CGColor;
        }
        layer.lineWidth = _lineWidth;
    }
    return layer;
}

// 设置默认参数
- (void)setDefaultProperty {
    
    _cornerRadius = 8;
    _arrowWidth = 30;
    _arrowHeight = 12;
    _arrowDirection = 1;
    _arrowPosition = 0.5;
    _arrowRadius = 3;
    _lineWidth = 1;
}

But there is a problem. I can see a line over the bubble, because the start point's position is wrong, so i add a method to get start point.

// 获得起点坐标
- (CGPoint)getStartPoint {
    NSMutableArray *points = [self keyPoints];
    CGPoint currentPoint = [[points objectAtIndex:6] CGPointValue];
    
    // 修改起点的位置,防止最后封闭路径的时候,露出一截
    switch (_arrowDirection) {
        case ArrowDirectionTop:
        {
            currentPoint.x = currentPoint.x + _cornerRadius;
        }
            break;
            
        case ArrowDirectionBottom:
        {
            currentPoint.x = currentPoint.x - _cornerRadius;
        }
            break;
            
        case ArrowDirectionLeft:
        {
            currentPoint.y = currentPoint.y - _cornerRadius;
        }
            break;
            
        case ArrowDirectionRight:
        {
            currentPoint.y = currentPoint.y + _cornerRadius;
        }
            break;
            
        default:
            break;
    }
    return currentPoint;
}

Then change the code CGPoint currentPoint = [[points objectAtIndex:6] CGPointValue]; to CGPoint currentPoint = [self getStartPoint]; at method - (CGPathRef )bubblePath.

Hope you can modify the code at your next version.

jiangbin1993 avatar Jul 02 '21 07:07 jiangbin1993

It doesn't work, borderColor doesn't work,

IIIOS avatar Mar 02 '23 03:03 IIIOS