मैं UIView
में कुछ पाठ प्रस्तुत करने के लिए निम्नलिखित का उपयोग कर रहा हूं। की तरह मैं उम्मीद [text drawInRect]
कीआईपैड/आईफोन - एनएसएसटींग drawInRect शब्द रैपिंग
- (void) drawRect:(CGRect)rect
{
NSString* text = @"asdf asdf asdf asdf asdf asdf asdf";
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextFillRect(context, rect);
CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip);
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextSetShouldSmoothFonts(context, YES);
UIFont* font = [UIFont fontWithName:@"ArialRoundedMTBold" size:20.0f];
CGSize textMaxSize = CGSizeMake(rect.size.width - 20.0f, rect.size.height);
CGSize textSize = [text sizeWithFont:font constrainedToSize:textMaxSize lineBreakMode:UILineBreakModeWordWrap];
CGRect textRect = CGRectMake(10.0f, 10.0f, textSize.width, textSize.height);
[text drawInRect:textRect withFont:font];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
}
कोई नहीं के पाठ लपेट। TextSize
ठीक से गणना की जाती है लेकिन ड्रॉ सिर्फ एक पंक्ति को प्रस्तुत कर रहा है।
अद्यतन:
हल हो गया।
सेटिंग्स CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip);
टेक्स्ट को UILineBreak
मोड के बावजूद क्लिप को क्लिप करने का कारण बन जाएगा। CGContextSetTextDrawingMode(context, kCGTextFillStroke);
को सेट करना इस समस्या को हल करता है।
यह बहुत अच्छा काम किया! – user523234