Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在界面生成器中,我们可以简单地将一条线拖到视图中。
但是我想以编程方式将一条线(例如,垂直线)分配到我的视图层次结构中,我应该在- addSubview:和- setFrame:方法之前初始化该框吗?
对不起,我自己解决。以下是代码:
NSBox *line = [[NSBox alloc] init]; [line setBoxType:NSBoxSeparator]; /* make it a line */ [line setFrame:NSMakeRect(0.0, 20.0, 300.0, 0.0)]; /* Or assign NSLayoutConstraint objects */ [self.view addSubview:line];