1

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Andrew Chang
  • 1,289
  • 1
  • 18
  • 38

1 Answers1

6

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];
holex
  • 23,961
  • 7
  • 62
  • 76
Andrew Chang
  • 1,289
  • 1
  • 18
  • 38