Problems with iOS drawing lines

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.