Note that there are some explanatory texts on larger screens.

plurals
  1. POPositioning NSTextField correctly with setFrame:
    primarykey
    data
    text
    <p><a href="http://f.cl.ly/items/120B2W082x1t1J012114/Screen%20Shot%202012-06-29%20at%2012.31.26.png" rel="nofollow noreferrer">NSView http://f.cl.ly/items/120B2W082x1t1J012114/Screen%20Shot%202012-06-29%20at%2012.31.26.png</a></p> <p>I am having problems positioning my NSTextFields inside my views so I hope you guys can help me. I have this NSView *theView with <code>[theView setFrame:NSMakeRect(10, 10, 64, 64)];</code> which positions the view exactly where I want it.</p> <p>But now I am trying to add a NSTextField as a subView to theView but something isn't right. Now the image <em>above is how it should be</em>.</p> <p>Here's my code and what it looks like:</p> <pre><code>primaryDigit = [[NSTextField alloc] init]; [primaryDigit setFrame:NSMakeRect(4, 6, 60, 58)]; [primaryDigit setFont:[NSFont fontWithName:@"Helvetica Neue" size:55]]; [primaryDigit setBezeled:NO]; [primaryDigit setEditable:NO]; [primaryDigit setSelectable:NO]; [primaryDigit setDrawsBackground:NO]; [primaryDigit setTextColor:[NSColor whiteColor]]; [primaryDigit setStringValue:@"2"]; [self addSubview:primaryDigit]; </code></pre> <p><a href="http://f.cl.ly/items/1C3A34241K3s3l2B2U3M/Screen%20Shot%202012-06-29%20at%2012.45.38.png" rel="nofollow noreferrer">wrong http://f.cl.ly/items/1C3A34241K3s3l2B2U3M/Screen%20Shot%202012-06-29%20at%2012.45.38.png</a></p> <p>And when I do <code>[primaryDigit setFrame:NSMakeRect(0, 0, 64, 64)];</code> the digit doesn't end up in the left lower corner but it does this:</p> <p><a href="http://f.cl.ly/items/2Y0X2F0H071M222b2W3P/Screen%20Shot%202012-06-29%20at%2012.49.51.png" rel="nofollow noreferrer">strange http://f.cl.ly/items/2Y0X2F0H071M222b2W3P/Screen%20Shot%202012-06-29%20at%2012.49.51.png</a></p> <p>Is there something fundamental that I don't understand about positioning these views? I'm quite the noobie but I still thought that I understand this. (Btw, the font is different in these images but that shouldn't cause a problem, I think?)</p> <p>Update: as 'dasdom' asked me to, here's the text field with a background colour <a href="http://f.cl.ly/items/463c161r0T3A1D3h0G3G/Screen%20Shot%202012-06-29%20at%2013.45.28.png" rel="nofollow noreferrer">backgroundcolor http://f.cl.ly/items/463c161r0T3A1D3h0G3G/Screen%20Shot%202012-06-29%20at%2013.45.28.png</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload