我有这个

CGRect container = CGRectMake(conX, conY, 220, 50);
    UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:container cornerRadius:5.0];
    [[UIColor blueColor] setFill];
    [path fillWithBlendMode:kCGBlendModeNormal alpha:0.7];
我想在它周围有一个灰色的边框,在网上看了很多东西,但看不到轻松的方法,有可能吗?

最佳答案

如果您不反对使用图层,则可以使用以下方法:

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

08-16 08:06