第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改NSView背景顏色的最佳方法

更改NSView背景顏色的最佳方法

動漫人物 2019-11-25 09:54:58
我在尋找改變的最佳途徑backgroundColor的NSView。我還希望能夠為設(shè)置適當(dāng)?shù)腶lpha蒙版NSView。就像是:myView.backgroundColor = [NSColor colorWithCalibratedRed:0.227f                                                    green:0.251f                                                     blue:0.337                                                    alpha:0.8];我注意到NSWindow有這種方法,我也不喜歡NSColorWheel或NSImage背景選項,但是如果它們是最好的,那就愿意使用。
查看完整描述

3 回答

?
侃侃爾雅

TA貢獻1801條經(jīng)驗 獲得超16個贊

是的,您自己的答案是正確的。您還可以使用可可方法:


- (void)drawRect:(NSRect)dirtyRect {

    // set any NSColor for filling, say white:

    [[NSColor whiteColor] setFill];

    NSRectFill(dirtyRect);

    [super drawRect:dirtyRect];

}

在Swift中:


class MyView: NSView {


    override func draw(_ dirtyRect: NSRect) {

        super.draw(dirtyRect)


        // #1d161d

        NSColor(red: 0x1d/255, green: 0x16/255, blue: 0x1d/255, alpha: 1).setFill()

        dirtyRect.fill()

    }


}


查看完整回答
反對 回復(fù) 2019-11-25
?
哈士奇WWW

TA貢獻1799條經(jīng)驗 獲得超6個贊

一個簡單,有效的解決方案是將視圖配置為使用Core Animation層作為其后備存儲。然后,您可以-[CALayer setBackgroundColor:]用來設(shè)置圖層的背景色。


- (void)awakeFromNib {

   self.wantsLayer = YES;  // NSView will create a CALayer automatically

}


- (BOOL)wantsUpdateLayer {

   return YES;  // Tells NSView to call `updateLayer` instead of `drawRect:`

}


- (void)updateLayer {

   self.layer.backgroundColor = [NSColor colorWithCalibratedRed:0.227f 

                                                          green:0.251f 

                                                           blue:0.337 

                                                          alpha:0.8].CGColor;

}


查看完整回答
反對 回復(fù) 2019-11-25
?
呼喚遠方

TA貢獻1856條經(jīng)驗 獲得超11個贊

想想我想出了怎么做:


- (void)drawRect:(NSRect)dirtyRect {

    // Fill in background Color

    CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];

    CGContextSetRGBFillColor(context, 0.227,0.251,0.337,0.8);

    CGContextFillRect(context, NSRectToCGRect(dirtyRect));

}


查看完整回答
反對 回復(fù) 2019-11-25
  • 3 回答
  • 0 關(guān)注
  • 1276 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號