UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Using a custom NSView inside an NSGridView

Forums > macOS

Hi,

I'm working my way through Hacking with macOS, and recently started messing around with NSGridView but I have an issue that's driving me crazy. When I create a new NSGridView with NSGridView(views: [[NSButtons]]) as per the "Odd one out" game it works fine and the buttons are displayed. However, I want to have my own custom views inside an NSGridView like NSGridView(views: [[MyCustomView]]) but I can't get it to display anything.

I guess I'm missing something trivial here like setting the height and width or something. I do as in the "Odd one out" game, like setting constraints and row height and column width on the grid view though. My custom view only draws a CGRect 20x20 right now, so that should give it a size, I guess?

Anyone see anything obvious that I have missed? :)

Also, my end goal is a pixel editor for sprites, so I'm not sure the NSGridView is the best option here. Maybe I should just do a custom NSView and "paint" the grid myself, and figure out mouse coordinates etc. in code. Any opinions on this?

Thanks for your attention :)

Regards, Andreas

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.