How to get a border on UIBezierPath

前端 未结 2 1253
花落未央
花落未央 2021-01-03 01:02

I have this

CGRect container = CGRectMake(conX, conY, 220, 50);
    UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:container cornerRadius:5.0]         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 01:23

    If you're not opposed to using layers, something like this could work for you:

    //create triangle path
    UIBezierPath* path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0, 30)];
    [path addLineToPoint:CGPointMake(100, 30)];
    [path addLineToPoint:CGPointMake(100, 0)];
    [path addLineToPoint:CGPointMake(0, 30)];
    
    //apply path to shapelayer 
    CAShapeLayer* greenPath = [CAShapeLayer layer];
    greenPath.path = path.CGPath;
    [greenPath setFillColor:[UIColor greenColor].CGColor];
    [greenPath setStrokeColor:[UIColor blueColor].CGColor];
    greenPath.frame=CGRectMake(0, 0,100,30);
    
    //add shape layer to view's layer
    [[self layer] addSublayer:greenPath];
    

提交回复
热议问题