Many controls want to add a line, common horizontal vertical, such as in a page header, cell, like TableView, such as the split line.
So I summed up several ways for you to refer to:
1. Use Cgcontext to paint, for example:
Uiimageview *imageview=[[uiimageview alloc] initWithFrame:self.view.frame]; [Self.view Addsubview:imageview]; Self.view.backgroundcolor=[uicolor Bluecolor]; Uigraphicsbeginimagecontext (imageView.frame.size); [Imageview.image drawinrect:cgrectmake (0, 0, ImageView.frame.size.width, imageView.frame.size.height)]; Cgcontextsetlinecap (Uigraphicsgetcurrentcontext (), kcglinecapround); Cgcontextsetlinewidth (Uigraphicsgetcurrentcontext (), 15.0); Line width cgcontextsetallowsantialiasing (uigraphicsgetcurrentcontext (), YES); Cgcontextsetrgbstrokecolor (Uigraphicsgetcurrentcontext (), 1.0, 0.0, 0.0, 1.0); Color Cgcontextbeginpath (Uigraphicsgetcurrentcontext ()); Cgcontextmovetopoint (Uigraphicsgetcurrentcontext (), 100, 100); Starting point coordinates cgcontextaddlinetopoint (Uigraphicsgetcurrentcontext (), 200, 100); End Coordinate Cgcontextstrokepath (Uigraphicsgetcurrentcontext ()); Imageview.image=uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext ();
2. Using UIView, I have seen students directly set UIView width or height as one of the lines:
UIView *line_view = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 320.F, 1.f)]; [Line_view Setbackgroundcolor:[uicolor Redcolor]; [Self.view Addsubview:line_view];
This is a red line, lol.
3. Using Uiimageview:
UIImage *separatorimage = [UIImage imagewithrendercolor:[uicolor Redcolor] Rendersize:cgsizemake (320.F, 1)]; Uiimageview *topseparatorview = [[Uiimageview alloc] initwithimage:separatorimage]; Topseparatorview.center = Cgpointmake (320.f*0.5, 0.5); [Self addsubview:topseparatorview];
This is actually adding a picture.
The above is summed up three kinds of horizontal lines, of course, there are many other ways, there are ideas can leave a message.
Problems with iOS drawing lines