cocoa – 在NSView中添加border和Rounded Rect

cocoa – 在NSView中添加border和Rounded Rect,第1张

概述在我的应用程序中,NSView应该有圆角矩形和边框,我试着跟随 static CGColorRef CGColorCreateFromNSColor (CGColorSpaceRef colorSpace, NSColor *color){ NSColor *deviceColor = [color 在我的应用程序中,NSVIEw应该有圆角矩形和边框,我试着跟随

static CGcolorRef CGcolorCreateFromNScolor (CGcolorSpaceRef                                            colorSpace,NScolor *color){    NScolor *devicecolor = [color colorUsingcolorSpacename:                            NSDeviceRGBcolorSpace];    float components[4];    [devicecolor getRed: &components[0] green: &components[1] blue:     &components[2] Alpha: &components[3]];    return CGcolorCreate (colorSpace,components);}

并在InitWithframe中添加了以下代码行

[[self layer] setCornerRadius:505];    [[self layer] setborderWIDth:500.0];    CGcolorSpaceRef colorSpace = CGcolorSpaceCreateDeviceRGB ();    CGcolorRef cgcolor = CGcolorCreateFromNScolor (colorSpace,[NScolor whitecolor]);    CGcolorSpaceRelease (colorSpace);    [[self layer] setbordercolor:cgcolor];

但没有任何影响,还有其他任何方法,

我可以猜到的另一种方法是,在drawRect绘制边框,但它似乎非常复杂,任何人都可以建议我任何其他方法

亲切的问候

罗汉

解决方法 谢谢你看这个,这个逻辑对我有用,

- (voID)drawRect:(NSRect)rect{   if([self hasborder])    [self drawborder:rect];}-(voID)drawborder:(NSRect)rect{    NSRect frameRect = [self bounds];    if(rect.size.height < frameRect.size.height)         return;    NSRect newRect = NSMakeRect(rect.origin.x+2,rect.origin.y+2,rect.size.wIDth-3,rect.size.height-3);    NSBezIErPath *textVIEwSurround = [NSBezIErPath bezIErPathWithRoundedRect:newRect xRadius:10 yRadius:10];    [textVIEwSurround setlinewidth:border_WIDTH];    [pbordercolor set];    [textVIEwSurround stroke];}
总结

以上是内存溢出为你收集整理的cocoa – 在NSView中添加border和Rounded Rect全部内容,希望文章能够帮你解决cocoa – 在NSView中添加border和Rounded Rect所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1026603.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存