Artem Novichkov
Artem Novichkov

Reputation: 2341

Rounded corners of NSCollectionViewItem

Simple question, but I can't find any answers... How I can change corner radius of NSCollectionViewItem instance?

Upvotes: 0

Views: 467

Answers (1)

Artem Novichkov
Artem Novichkov

Reputation: 2341

view of NSCollectionViewItem doesn't have layer by default. You need to set wantsLayer to true, for example:

import Cocoa

class TestCellItem: NSCollectionViewItem {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.wantsLayer = true
        view.layer?.backgroundColor = NSColor.red.cgColor
    }

    override func viewDidLayout() {
        super.viewDidLayout()
        view.layer?.cornerRadius = 20
    }
}

Upvotes: 1

Related Questions