How to set NSView size programmatically?

前端 未结 3 1106
小鲜肉
小鲜肉 2020-12-31 16:46

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

    -(void)awakeFromNib {
        self.frame.size.width   = 1280;   // Does nothing...
        self.fra         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-31 17:22

    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;
        //...
    }
    

提交回复
热议问题