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

2.1k views Asked by At

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

1

There are 1 answers

5
Łukasz On BEST ANSWER

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.