ykpopview.m//drawansample////Created by Goshong on 15/9/6.//Copyright (c) 2015 Yinyakun. All rights reserved.//#import "YKPopView.h" #define MENUGAP 7@implementation ykpopview-(instancetype) initWithFrame: ( CGRect) frame {self = [super Initwithframe:frame]; if (self) {self.backgroundcolor = [uicolor Clearcolor]; } return self;} Only override Drawrect:if-perform custom drawing.//an empty implementation adversely affects performance during a nimation.-(void) DrawRect: (cgrect) Rect {//Drawing code cgfloat width = rect.size.width; CGFloat height = rect.size.height; CGFloat radius = 3; Get Cgcontext, note that Uikit uses a specialized function cgcontextref context = Uigraphicsgetcurrentcontext (); Move to the initial point cgcontextmovetopoint (context, radius, menugap); Draws a 1th line and 1th 1/4 arc cgcontextaddlinetopoint (context, Width * 5/6-6,menugap); Cgcontextaddlinetopoint (Context, Width * 5/6,0); Cgcontextaddlinetopoint (Context, Width * 5/6 + 6,menugap); Cgcontextaddlinetopoint (context, Width-radius, menugap); Cgcontextaddarc (context, Width-radius, radius + menugap, radius, -0.5 * m_pi, 0.0, 0); Draw 2nd line and 2nd 1/4 Arc cgcontextaddlinetopoint (context, width, height-radius-menugap); Cgcontextaddarc (context, Width-radius, height-radius-menugap, radius, 0.0, 0.5 * m_pi, 0); Draw 3rd Line and 3rd 1/4 arc cgcontextaddlinetopoint (context, radius, height-menugap); Cgcontextaddarc (context, radius, height-radius-menugap, radius, 0.5 * m_pi, M_PI, 0); Draws a 4th line and 4th 1/4 Arc cgcontextaddlinetopoint (context, 0, radius + menugap); Cgcontextaddarc (context, radius, radius + menugap, radius, M_PI, 1.5 * m_pi, 0); Closed path Cgcontextclosepath (context); [[Uicolor Redcolor] setfill]; Cgcontextdrawpath (context, Kcgpathfill);}
Customize a view.
iOS from top one view