I wan to design a settings page, in which I have to draw lines between multiple labels, what is the best way to do this, I have googled around, got to know about CGContextRef
approach. Is this the proper way, I need to have a line between labels (consecutively). Can I go ahead with this approach or any other best way is there.
Separating multiple UILabels with a line IOS
1.2k Views Asked by Newbee At
3
There are 3 best solutions below
0

May be just add UIView between labels? Something Like this:
UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
//Label settings
[self addSubview:topLabel];
[topLabel release];
UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(topLabel.frame.origin.x, CGRectGetMaxY(topLabel.frame), topLabel.frame.size.width, 2)];
separator.backgroundColor = [UIColor blackColor];
UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(separator.frame), 320, 20)];
//Label settings
[self addSubview:bottomLabel];
[bottomLabel release];
0

Couldn't you just create a custom UIView class with a UILabel and a UIView as the subviews of this custom view class?
class CustomView : UIView
{
UIView *line;
UILabel *label;
}
@property(nonatomic, retain) UIView *line;
@property(nonatomic, retain) UILabel *label;
For the UIView subview, you can tell it to use the width of the parent UIView.
I have given base view as dark color and I am adding labels as white, I am giving a line gap between two labels its looking like a line. No extra work :)