ios - How to draw a disk with a number/string inside? -
so far know how draw disk, use method:
func drawdisk(color: uicolor, rectfordisk: cgrect = cgrectmake(0.0, 0.0, 1.0, 1.0), withstroke: bool) -> uiimage { uigraphicsbeginimagecontextwithoptions(rectfordisk.size, false, 0.0) let context = uigraphicsgetcurrentcontext() cgcontextsetfillcolorwithcolor(context, color.cgcolor) cgcontextfillellipseinrect(context, rectfordisk) let rectforcircle = cgrectmake(0.5, 0.5, rectfordisk.size.width - 1, rectfordisk.size.height - 1) cgcontextsetlinewidth(context, withstroke ? 1.0 : 0) cgcontextsetstrokecolorwithcolor(context, uicolor.blackcolor().cgcolor) cgcontextaddellipseinrect(context, rectforcircle) cgcontextstrokepath(context) let image = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() return image } what don't know add text in drawing. i'm not sure it's possible. thought adding label on top of wondering if there better/proper way.
a simple way you're after use label, on own, , set corner radius of layer , set background colour. set layer clip. if choose corner radius correctly can have circular label , grow oblong bubble if required text contains.

Comments
Post a Comment