FREE TRIAL: Accelerate your app development career with 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

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

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.