【问题标题】:Specific Round Corner of NSViewNSView的特定圆角
【发布时间】:2020-07-07 08:34:35
【问题描述】:

我想要一个带有收音机的 NSView 的特定角落,但我不知道该怎么做。 对于所有角落,我都在使用

class StyledButton: NSView {
let roundLayer: CALayer = CALayer()

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
    setup()
}

override init(frame: CGRect) {
    super.init(frame: frame)
    setup()
}

func setup() {
    self.wantsLayer = true
    self.layer?.addSublayer(roundLayer)
    roundLayer.frame = self.bounds
    roundLayer.cornerRadius = 3
    roundLayer.backgroundColor = NSColor.redColor().CGColor
}

}

【问题讨论】:

    标签: macos nsview round-corner


    【解决方案1】:

    你可以使用maskedCorners:

        layerMinXMinYCorner = bottom left corner
        layerMaxXMinYCorner = bottom right corner
        layerMaxXMaxYCorner = top right corner
        layerMinXMaxYCorner = top left corner
    

    这是一个仅圆角的示例 bottom right and top right 角:

            let rightRoundView = NSView(frame: CGRect(x: 100, y: 100, width: 128, height: 128))
            rightRoundView.wantsLayer = true
            rightRoundView.layer?.cornerRadius = 25
            if #available(OSX 10.13, *) {
                rightRoundView.layer?.maskedCorners = [.layerMaxXMinYCorner, .layerMaxXMaxYCorner]
            } else {
                // Fallback on earlier versions
            }
    

    【讨论】:

      猜你喜欢
      • 2019-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 2022-11-11
      相关资源
      最近更新 更多