IOS Paint bubbles (bubble)

Source: Internet
Author: User

This article is about the iOS code draw bubbles, hand teach you to draw a bubble, other shapes please the reader to try their own, I hope you have fun!

speechbubbleview.m//demo////Created by mygame on 15/3/4.//Copyright (c) 2015 Mygame. All rights reserved.//#import "SpeechBubbleView.h" #import <CoreGraphics/CoreGraphics.h> #define Kpopuptriangleheigh 12#define kpopuptrianglewidth 22#define kborderoffset 0//0.5f@implementation SpeechBubbleView-(    Instancetype) initWithFrame: (cgrect) frame{self = [super Initwithframe:frame];    if (self) {self.backgroundcolor = [uicolor Purplecolor]; } return self;}        -(void) DrawRect: (cgrect) rect {[Super Drawrect:rect];    CGFloat vieww = rect.size.width;        CGFloat VIEWH = rect.size.height;    CGFloat strokewidth = 1;    CGFloat Borderradius = 10;        CGFloat offset = strokewidth + kborderoffset;    Cgcontextref context = Uigraphicsgetcurrentcontext (); Cgcontextsetlinejoin (context, kcglinejoinround); Cgcontextsetlinewidth (context, strokewidth); Sets the brush width cgcontextsetstrokecolorwithcolor (context, [Uicolor Lightgraycolor]. Cgcolor); Set Brush faceColor Cgcontextsetfillcolorwithcolor (context, [Uicolor Lightgraycolor]. Cgcolor); Set Fill color//Draw triangle/*---/*
/*
Draw the red part
*    /Cgcontextbeginpath (context);    Cgcontextmovetopoint (context, Borderradius+offset, viewh-kpopuptriangleheigh-offset);    Cgcontextaddlinetopoint (Context, round ((vieww-kpopuptrianglewidth)/2.0f) + offset, Viewh-kpopuptriangleheigh-offset);    Cgcontextaddlinetopoint (context, round (vieww/2.0f), viewh-offset);    Cgcontextaddlinetopoint (context, round (vieww+kpopuptrianglewidth)/2.0f) +offset,  Viewh-kpopuptriangleheigh-offset);    //Draw the rest
/*
 
  

* /Cgcontextaddarctopoint (context, Vieww-offset, Viewh-kpopuptriangleheigh-offset, Vieww-offset, Kpopuptriangleheigh+offset, borderradius-strokewidth); Cgcontextaddarctopoint (context, Vieww-offset, offset, vieww-borderradius-offset, offset, borderradius-strokewidth); Cgcontextaddarctopoint (context, offset, offset, offset, borderradius+offset, borderradius-strokewidth); Cgcontextaddarctopoint (context, offset, viewh-kpopuptriangleheigh-offset, Borderradius+offset, Viewh-kpopuptriangleheigh-offset, borderradius-strokewidth); Cgcontextclosepath (context); Cgcontextdrawpath (context, kcgpathfillstroke);} @end

For Cgcontextaddarctopoint interface explanation please click here

IOS Paint bubbles (bubble)

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: info-contact@alibabacloud.com 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.