如何以编程方式设置NSView大小? [英] How to set NSView size programmatically?

查看:168
本文介绍了如何以编程方式设置NSView大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程方式设置NSView的大小,例如

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.
        ...

(Mac OSX的)笔尖中的大小设置可以正常运行,但是我想用代码来完成.

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

推荐答案

调用self.frame时,它将返回框架中的数据,而不是指针.因此,结果的任何变化都不会反映在视图中.为了更改视图,您必须在更改后设置新框架:

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

这篇关于如何以编程方式设置NSView大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆