Sample code for creating a NSTextField “label”?

前端 未结 6 1088
灰色年华
灰色年华 2020-12-24 01:53

In my desktop Mac OS X app, I\'d like to programatically create a NSTextField \"label\" which has the same behavior and properties as a typical label created in Interface Bu

6条回答
  •  猫巷女王i
    2020-12-24 02:36

    This can be tricky to get right. I don't have the recipe for an exact replica handy, but when I've been stuck in a similar situation, here's what I do:

    1. Create a UI element in IB.
    2. Add an outlet to it from my controller class.
    3. Break in gdb in awakeFromNib or whatever.
    4. From the gdb prompt, "p *whateverOutlet" ... this will show you the C struct contents of the label NSTextField that IB set up.

    By looking at all the myriad values in there, you can get a lot of guesses about what you're neglecting to set. Usually it ends up being some magic combination of bezel and border settings, that gets you where you want to be.

提交回复
热议问题