आपको अपने रन प्रतिनिधि को अपनी जिम्मेदार स्ट्रिंग में वर्णों की एक श्रृंखला के लिए एक विशेषता के रूप में जोड़ना चाहिए। Core Text String Attributes देखें। ड्राइंग करते समय, कोर टेक्स्ट उस कॉलम का आकार प्राप्त करने के लिए आपके कॉलबैक को कॉल करेगा। (ध्यान दें कि वहाँ कोई स्मृति प्रबंधन कोड यहाँ है कि)
अद्यतन
यह एक दृश्य के एक साधारण पाठ ड्राइंग के लिए एक नमूना कोड है।
@implementation View
/* Callbacks */
void MyDeallocationCallback(void* refCon){
}
CGFloat MyGetAscentCallback(void *refCon){
return 10.0;
}
CGFloat MyGetDescentCallback(void *refCon){
return 4.0;
}
CGFloat MyGetWidthCallback(void* refCon){
return 125;
}
- (void)drawRect:(CGRect)rect {
// create an attributed string
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:@"This is my delegate space"];
// create the delegate
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateVersion1;
callbacks.dealloc = MyDeallocationCallback;
callbacks.getAscent = MyGetAscentCallback;
callbacks.getDescent = MyGetDescentCallback;
callbacks.getWidth = MyGetWidthCallback;
CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, NULL);
// set the delegate as an attribute
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attrString, CFRangeMake(19, 1), kCTRunDelegateAttributeName, delegate);
// create a frame and draw the text
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, rect);
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, attrString.length), path, NULL);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextSetTextPosition(context, 0.0, 0.0);
CTFrameDraw(frame, context);
}
@end
पाठ में "प्रतिनिधि" और "अंतरिक्ष" के बीच अंतरिक्ष चरित्र का आकार रन प्रतिनिधि द्वारा नियंत्रित किया जाता है।
मैंने पहले ही ऐसा किया है लेकिन यह मदद नहीं कर रहा है। प्रलेखन स्वयं CTRunDelegate के बारे में अधिक जानकारी नहीं देता है। यदि आपके पास CTRunDelegate के लिए कोई नमूना कोड है, तो यह बहुत मददगार होगा। – tek3
मुझे आपका जवाब देखने से पहले जवाब मिला लेकिन आपने मुझे सही जवाब देने के लिए प्रयास किया, इसलिए यह बकाया आपको जाता है। Thanx आपकी प्रतिक्रिया के लिए बहुत कुछ। – tek3
हाय मो, मुझे आपके आवेदन के लिए आपसे कुछ और मदद चाहिए। क्या आप मेरी मदद करने में रुचि रखते हैं ?? – tek3