चरण 1: एक वस्तु UIView
से
विरासत में मिला बनाएं चरण 2: ओवरराइड - (शून्य) drawRect: (CGRect) रेक्ट विधि
चरण 3: इस विधि
/* Define some defaults */
float padding = 10.0f;
/* Get the graphics context for drawing */
CGContextRef ctx = UIGraphicsGetCurrentContext();
/* Core Text Coordinate System is OSX style */
CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
CGContextTranslateCTM(ctx, 0, self.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGRect textRect = CGRectMake(padding, padding, self.frame.size.width - padding*2, self.frame.size.height - padding*2);
/* Create a path to draw in and add our text path */
CGMutablePathRef pathToRenderIn = CGPathCreateMutable();
CGPathAddRect(pathToRenderIn, NULL, textRect);
/* Add a image path to clip around, region where you want to place image */
CGRect clipRect = CGRectMake(padding, self.frame.size.height-50, 50, 40);
CGPathAddRect(pathToRenderIn, NULL, clipRect);
/* Build up an attributed string with the correct font */
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.Text];
//setFont
CTFontRef font = CTFontCreateWithName((CFStringRef) [UIFont systemFontOfSize:10].fontName, [UIFont systemFontOfSize:10].lineHeight, NULL);
CFAttributedStringSetAttribute((CFMutableAttributedStringRef) attrString, CFRangeMake(0, attrString.length), kCTFontAttributeName,font);
//set text color
CGColorRef _white=[UIColor whiteColor].CGColor;
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)(attrString), CFRangeMake(0, attrString.length),kCTForegroundColorAttributeName, _white);
/* Get a framesetter to draw the actual text */
CTFramesetterRef fs = CTFramesetterCreateWithAttributedString((CFAttributedStringRef) attrString);
CTFrameRef frame = CTFramesetterCreateFrame(fs, CFRangeMake(0, attrString.length), pathToRenderIn, NULL);
/* Draw the text */
CTFrameDraw(frame, ctx);
/* Release the stuff we used */
CFRelease(frame);
CFRelease(pathToRenderIn);
CFRelease(fs);
लिए निम्न कोड जोड़ें
चरण 4: निम्नानुसार उपयोग करें;
TextLayoutView *TextWrappingImage=[[TextLayoutView alloc] init...your own constructor...];
TextWrappingImage.backgroundColor=[UIColor clearColor];
[cell addSubview:TextWrappingImage]; //Add as subview where you want
मुझे लगता है कि मुझे आपकी मदद चाहिए। मैं आपके ब्लॉग पोस्ट में कोड को काफी समझ नहीं पा रहा हूं। क्या आप इस विषय पर एक लेख लिख सकते हैं? धन्यवाद! – nonamelive
इस बारे में भूल गए नहीं है; इसे एक साथ रखने के लिए बस थोड़ा सा लिया गया है। –
यह थोड़ा मोटा है, लेकिन उम्मीद है कि यह आपको सही दिशा में ले जायेगा। http://robnapier.net/blog/wrapping-text-around-shape-with-coretext-540 –