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