且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在NSImage周围绘制彩色边框?

更新时间:2023-11-15 13:45:04

尝试这样而不创建子类也是可能的。您还可以相应地设置宽度和半径: -

Try like this without creating subclass also it is possible. Also you can set the width ans radius accordingly:-

[imgView setWantsLayer:YES];
imgView.layer.borderWidth = 1.0;
imgView.layer.cornerRadius = 8.0;
imgView.layer.masksToBounds = YES;
CGColorRef color = CGColorRetain([NSColor colorWithCalibratedRed:0 green:100 blue:0 alpha:0.5f].CGColor);
[imgView.layer setBorderColor:color];