我正在开发一个我必须使用的iPad应用程序CTRunDelegate.我已经定义了所有所需的即回调CTRunDelegateGetAscentCallback,CTRunDelegateGetDescentCallback,CTRunDelegateGetWidthCallback.我不知道如何使用CTRunDelegateRef我正在创建的对象.现在发生的事情是我的回调没有被调用.
任何有关这方面的指示都将受到高度赞赏.
Thanx提前.
我有一个附有图片的属性字符串(NSTextAttachment)。一切正常,但是我遇到了无法解决的截断问题。
在示例中,假设字符串##是图像。所以我的弦看起来像Hello world! ##。在段落样式上设置了尾部截断。
现在,如果空间受到限制,则文本将被省略号省略(这是我想要的)。但不幸的是,图像也被截断了。
所以结果是这样的:
Hello w...
Run Code Online (Sandbox Code Playgroud)
但我希望它看起来像:
Hello...##
Run Code Online (Sandbox Code Playgroud)
也就是说,我希望图像附件不会被截断,它应该始终可见。
附件的原因是我希望图像始终位于字符串的末尾,因此,当文本较短时,图像位于末尾,并且当文本换行时,我也希望图像位于字符串末尾结束。尝试手动将图像“放在外面”将不起作用,因为文本无法正确地被截断。
因此,有没有办法告诉您NSAttributedString不要截断图像?
产生属性字符串的示例代码:
NSString *title;
NSMutableAttributedString *attributedString;
NSMutableParagraphStyle *paragraph;
NSDictionary *attributes;
NSTextAttachment *attachment;
paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraph.hyphenationFactor = 1.0;
paragraph.lineBreakMode = NSLineBreakByTruncatingTail;
attributes = @{
NSForegroundColorAttributeName : [self titleTextColor],
NSParagraphStyleAttributeName : paragraph,
};
title = @"Hello world!";
attributedString = [[NSMutableAttributedString alloc] initWithString:title
attributes:attributes];
attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"myImage"];
[attributedString appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
[attachment release];
self.titleLabel.attributedText = …Run Code Online (Sandbox Code Playgroud)