ios - Example of NSTextContainer with non regular shape? -
hi i'm working new textkit
api ios7 , i'm trying produce uitextview
irregular shape. far have in view controller:
-(void) loadview { self.view = [[uiview alloc] initwithframe:cgrectmake(0,0,320,548)]; nstextstorage *textstorage = [[nstextstorage alloc] init]; nslayoutmanager *layoutmanager = [[nslayoutmanager alloc] init]; [textstorage addlayoutmanager: layoutmanager]; basetextcontainer *textcontainer = [[basetextcontainer alloc] initwithsize:cgsizemake(100, 100)]; [layoutmanager addtextcontainer: textcontainer]; basetextview *textview = [[basetextview alloc] initwithframe:cgrectmake(110,124, 100, 100) textcontainer:textcontainer]; textview.backgroundcolor = [uicolor bluecolor]; textview.editable = yes; [self.view addsubview:textview]; }
then in subclassed nstextcontainer
, want have mutablepath
drawn shape of text container, not sure how accomplish this. have:
- (bool) issimplerectangulartextcontainer { return no; } - (void) drawlayer:(calayer *)layer incontext:(cgcontextref)ctx { nslog(@"test"); cgcontextref context = ctx; cgsize layersize = layer.frame.size; cgaffinetransform transform = cgaffinetransformmakescale(layersize.width / self.initialsize.width, layersize.height / self.initialsize.height); cgmutablepathref newgraphicmutablepath = cgpathcreatemutablecopybytransformingpath(self.mutablepath, &transform); cgcontextaddpath(context, newgraphicmutablepath); cgpathrelease(newgraphicmutablepath); cgcontextsetfillcolorwithcolor(context, [uicolor redcolor].cgcolor); cgcontextdrawpath(context, kcgpathfill); }
just bit confused how work. cannot find example anywhere of nstextcontainer
irregular shape.
there no need code constructing text kit stack, not modifying architecture of stack. start normal uitextview - let's it's self.textview
- , assign 1 or more uibezierpath objects exclusion paths:
self.tv.textcontainer.exclusionpaths = myarrayofbezierpaths;
these paths exclusion paths, ellipse want make 4 paths, each 1 describing corner of text container.
alternatively, can build text kit stack insert own text container subclass, , modify text allowed go overriding linefragmentforproposedrect:
, perhaps similar here: https://github.com/mattneub/programming-ios-book-examples/blob/master/bk2ch10p537exclusionpath2/ch23p813textkitshapes/mytextcontainer.swift
some experiments:
Comments
Post a Comment