如何在swift中设置alphaValue?

时间:2014-10-09 12:55:36

标签: macos swift xcode6 nsview

我有一个NSView的子类,我不知道我应该调用什么函数来改变alpha值。在目标c很容易:

 [self setAlphaValue: 0.5];

但是在迅捷中我找不到合适的功能。

override func drawRect(dirtyRect: NSRect){
        backgroundColor.set()
    //  self alphaValue(0.56)


        let bezierPath = NSBezierPath(roundedRect:self.bounds, xRadius:self.frame.size.width/2, yRadius:self.frame.size.width/2)
        bezierPath.lineWidth = 2.0
        bezierPath.fill()
    }

谢谢,抱歉我的英语不好。

1 个答案:

答案 0 :(得分:1)

Objective-C代码

[self setAlphaValue: 0.5];

可以使用属性表示法编写为

self.alphaValue = 0.5;

直接转换为Swift为

self.alphaValue = 0.5