【问题标题】:How to set alphaValue in swift ?如何在 swift 中设置 alphaValue?
【发布时间】:2014-10-09 12:55:35
【问题描述】:

我有一个 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()
    }

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

【问题讨论】:

    标签: macos swift xcode6 nsview


    【解决方案1】:

    Objective-C 代码

    [self setAlphaValue: 0.5];
    

    可以使用属性表示法写成

    self.alphaValue = 0.5;
    

    直接翻译成 Swift 为

    self.alphaValue = 0.5
    

    【讨论】:

      猜你喜欢
      • 2019-05-19
      • 2016-02-18
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 2021-06-24
      • 2014-07-26
      相关资源
      最近更新 更多