Hi all,
I am trying to bold the selected text of UITextView
.For that i am using coreText approach.In this i am able to bold the selected text and display on context using NSMutableAtrributedString
.
-(void)drawRect:(CGRect)rect
{
NSLog(@"return str.....%@",[PISTrialViewController returnString]);
NSMutableAttributedString *string = [[NSMutableAttributedString alloc]
initWithString:[PISTrialViewController returnString]];
NSLog(@"attrrrr.....%@",string);
tempRange=[PISTrialViewController returnRange];
// make a few words bold
CTFontRef helvetica = CTFontCreateWithName(CFSTR("Helvetica"), 14.0, NULL);
CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica-Bold"), 14.0, NULL);
NSLog(@"location.....%d",tempRange.location);
NSLog(@"length.....%d",tempRange.length);
[string addAttribute:(id)kCTFontAttributeName
value:(id)helveticaBold
range:NSMakeRange(tempRange.location,tempRange.length)];
// layout master
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(
(CFAttributedStringRef)string);
// left column form
CGMutablePathRef leftColumnPath = CGPathCreateMutable();
CGPathAddRect(leftColumnPath, NULL,
CGRectMake(0, 0,
self.bounds.size.width,
self.bounds.size.height));
// left column frame
CTFrameRef leftFrame = CTFramesetterCreateFrame(framesetter,
CFRangeMake(0, 0),
leftColumnPath, NULL);
context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
// draw
CTFrameDraw(leftFrame, context);
// cleanup
CFRelease(leftFrame);
CGPathRelease(leftColumnPath);
CFRelease(framesetter);
CFRelease(helvetica);
CFRelease(helveticaBold);
[string release];
}
I have selected some text from UITextView and send that text to subclass of UIView where i have written this method(drawRect).The context drawn in uiview displays the selected t开发者_如何学Pythonext as bold.But now i am unable to select the text further.How can i do that?
How to save/retrieve NSMutableAtrributedString
in/from sqlite database?
How can i send it on server?(in which format?)
NSMutableAtrributedString implements the NSCoding protocol, so you can use NSKeyedArchiver to serialize them.
精彩评论