Text 单触式核心文本框架设置器
使用monotouch,我尝试在多行上显示一个核心文本元素。我尝试使用的示例来自第17页。我遇到的一个问题是找不到CFMutableAttributedStringRef的等效项,因此我尝试将其替换为NSAttributedString,但是下面的代码没有显示任何内容。是否有人知道monotouch中的此类示例,或者知道以下内容不起作用的原因。谢谢Text 单触式核心文本框架设置器,text,xamarin.ios,core,paragraph,Text,Xamarin.ios,Core,Paragraph,使用monotouch,我尝试在多行上显示一个核心文本元素。我尝试使用的示例来自第17页。我遇到的一个问题是找不到CFMutableAttributedStringRef的等效项,因此我尝试将其替换为NSAttributedString,但是下面的代码没有显示任何内容。是否有人知道monotouch中的此类示例,或者知道以下内容不起作用的原因。谢谢 public override void Draw (RectangleF rect) { base.Draw (r
public override void Draw (RectangleF rect)
{
base.Draw (rect);
CGContext context = UIGraphics.GetCurrentContext ();
context.TextMatrix = new CGAffineTransform();
CGPath path = new CGPath();
path.AddRect ( this.Bounds );
// created dictionary so this line does not crash
NSAttributedString stringToDraw = new NSAttributedString( "Hello", new NSDictionary() );
CTFramesetter framesetter = new CTFramesetter(stringToDraw);
CTFrame frame = framesetter.GetFrame( new NSRange(0,0), path, null );
frame.Draw( context );
}
不确定这是否正确,但接下来 从苹果的
CFMutableAttributedStringRef
参考文档:
重要提示:为属性字符串设置的属性字典必须
始终使用kCFCopyStringDictionaryKeyCallbacks为其
字典键回调和其
价值回调;否则这就是一个错误
因此,我认为使用
new NSDictionary()
参数创建它是不够的。在编写/测试MonoTouch.CoreText框架时,我将这些示例中的大部分移植到了MonoTouch。然后显然完全忘记了将它们合并到上游-/
也就是说,看看你链接到的PDF中的大多数示例(几乎是一行接一行)的端口
根据我的CoreTextDemo.cs
,您缺少:
- 正确的
调用:CGAffineTransform.MakeScale()
context.TextMatrix=CGAffineTransform.MakeScale(1f,-1f)代码>
- 您没有使用
。(nsmutableAttributeString
映射到CFMutableAttributedStringRef
)NSMutableAttributedString
- 您没有处理您的
,也没有处理您的帧设置器
帧
可能还有其他代码,但当时的
CoreTextDemo.cs
代码的工作原理与Objective-C代码相当。感谢您的回复,我在另一个示例中使用了“new NSDictionary()”处理核心文本。就在我尝试使用framesetter时,我什么也看不到。除了添加TranslateCTM和ScaleCTM,我还必须删除以下代码:context.TextMatrix=CGAffineTransform.MakeScale(1f,-1f)代码>。谢谢你们两个!很多人告诉我这是不可能的,我应该放弃使用UIWebView。我很高兴我找到了这个例子。