iphone - 如何在 UIBezierPath 上获取边框

标签 iphone objective-c ios

我有这个

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

关于iphone - 如何在 UIBezierPath 上获取边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12083229/

相关文章:

ios - 同时独立的手势

iphone - 我在 plist 中的信息未保存

objective-c - 如何让横向启动图像在启动时实际出现?

ios - Admob 智能横幅广告不会在设备旋转时更新

html - 如何使音乐文件的 URL 在 iOS 上的 VLC 中播放?

iphone - 类似于 iPhone 版 Twitter 的导航风格

iphone sqlite 内存泄漏 [NSString stringWithUTF8String :(char*)sqlite3_column_text

ios - 在字典/HashMap中存储KeyPath

iphone - 核心数据和后台线程的问题

iphone - 在特定时间调用方法