5

OS Xで角が丸いNSVisualEffectViewを表示するにはどうすればよいですか?

NSVisualEffectView を追加するコード:

let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 300, 300))
visualEffectView.material = NSVisualEffectMaterial.Dark
visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow
self.addSubview(visualEffectView)
4

3 に答える 3

10

NSVisualEffectViewに設定してから、バッキング レイヤーの を設定することwantsLayerで、レイヤー バッキングビューを有効にすることができます。truecornerRadius

    let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 300, 300))
    visualEffectView.material = NSVisualEffectMaterial.Dark
    visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow
    visualEffectView.wantsLayer = true
    visualEffectView.layer?.cornerRadius = 15.0
    self.view.addSubview(visualEffectView)

これにより、角が丸くなった効果ビューが得られます。

ここに画像の説明を入力

于 2015-08-17T06:04:37.217 に答える
2

NSVisualEffectViewmaskImageビューを任意の形状にクリップするために使用できるプロパティがあります。

ヘッダーから:

/* The mask image masks this view. It is best to set this to the
   smallest mask image possible and properly set the image.capInsets to
   inform the image on how to stretch the contents when it is used as a
   mask. Setting the maskImage on an NSVisualEffectView that is the
   window.contentView will correctly set the window's shadow.
 */
public var maskImage: NSImage?

たとえば、NSImage角を丸くした を使用して、 をcapInsets角の半径に設定し、resizingModeをに設定できます.stretch

于 2016-07-01T19:26:28.513 に答える