How to add an line of NSBox programmatically?

2.6k Views Asked by At

In interface builder, we can simply drag a line to the view.

But I want to programmatically assign a line (for example, vertical line) into my view hierarchy, what should I initialize the box before - addSubview: and - setFrame: methods?

1

There are 1 best solutions below

0
Andrew Chang On BEST ANSWER

Sorry, I solve it myself. Here are the codes:

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];