Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set NSView size programmatically?

How do you set the size of NSView programmically e.g.

    -(void)awakeFromNib {
        self.frame.size.width   = 1280;   // Does nothing...
        self.frame.size.height  = 800;    // ...neither does this.
        ...

The size setup in the nib (of Mac OSX) works OK, but I want to do it in code.

like image 978
Robin Pain Avatar asked Dec 17 '10 17:12

Robin Pain


1 Answers

When you call self.frame, it returns the data in the frame, and not a pointer. Therefore, any change in the result is not reflected in the view. In order to change the view, you have to set the new frame after you make changes:

- (void)awakeFromNib {
    NSRect f = self.frame;
    f.size.width = 1280;
    f.size.height = 800;
    self.frame = f;
    //...
}
like image 152
ughoavgfhw Avatar answered Nov 22 '22 20:11

ughoavgfhw