ios - How to make kCGPathStroke work in Swift 2? -
i getting 2 errors try upgrade app swift 2.
the 2 errors are:
use of unresolved identifier 'kcgpathstroke'
and:
cannot convert value of type 'nsmutabledictionary' expected argument type '[string : anyobject]?'
both issues commented on in code below. checked documentation , looks kcgpathstroke
still exists, confused why broken. doing wrong?
import uikit import coregraphics class mibadgelabel: uilabel { override func drawrect(rect: cgrect) { // drawing code let ctx: cgcontextref = uigraphicsgetcurrentcontext()! let borderpath: uibezierpath = uibezierpath(roundedrect: rect, byroundingcorners:uirectcorner.allcorners, cornerradii: cgsizemake(10.0, 10.0)) cgcontextsetfillcolorwithcolor(ctx, uicolor.whitecolor().cgcolor) cgcontextsavegstate(ctx) cgcontextaddpath(ctx, borderpath.cgpath) cgcontextsetlinewidth(ctx, 4.0) cgcontextsetstrokecolorwithcolor(ctx, uicolor.clearcolor().cgcolor) cgcontextdrawpath(ctx, kcgpathstroke) //swift 2 error cgcontextrestoregstate(ctx) cgcontextsavegstate(ctx) // cgcontextsetfillcolorwithcolor(ctx, uicolor.whitecolor().cgcolor) var textframe: cgrect = rect let labelstring: nsstring = self.text! nsstring let textsize: cgsize = labelstring.sizewithattributes([nsfontattributename : uifont.systemfontofsize(13.0)]) textframe.size.height = textsize.height textframe.origin.y = rect.origin.y + ceil((rect.size.height - textframe.size.height) / 2.0) let paragraphstyle: nsmutableparagraphstyle = nsmutableparagraphstyle(); paragraphstyle.alignment = .center var attributes: nsmutabledictionary = [nsfontattributename: uifont.systemfontofsize(13.0), nsforegroundcolorattributename : uicolor.whitecolor(), nsparagraphstyleattributename:paragraphstyle] labelstring.drawinrect(textframe, withattributes: attributes) // swift 2 error } }
first error:
cgcontextdrawpath(ctx, kcgpathstroke)
like this:
cgcontextdrawpath(ctx, .stroke)
second error:
var attributes: nsmutabledictionary = [ nsfontattributename: uifont.systemfontofsize(13.0), nsforegroundcolorattributename : uicolor.whitecolor(), nsparagraphstyleattributename:paragraphstyle ]
like this:
let attributes = [ nsfontattributename: uifont.systemfontofsize(13.0), nsforegroundcolorattributename : uicolor.whitecolor(), nsparagraphstyleattributename:paragraphstyle ]
Comments
Post a Comment