Search code examples
macoscocoaswiftnscolorcgcolor

How to get cgcolor from nscolor with pattern image using swift?


Here my line

NSView *myview
[self.myview.layer setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"myImageName.png"]].CGColor];

How to write these lines in swift language

.

Thanks


Solution

  • I don't understand beginning of your code (why self.myview.layer if myview is declared one line above), but rest should be something like this:

    self.myview.layer?.backgroundColor = NSColor(patternImage:NSImage(named: "myImageName.png")!).CGColor
    

    Let me know if it works.