Xamarin.ios 如何对齐AttributeText?

Xamarin.ios 如何对齐AttributeText?,xamarin.ios,Xamarin.ios,我有一个包含属性文本的UITextView。 我正在尝试将其居中(因为文本具有属性,textView.TextAlignment不起作用) 我该怎么办? 我试过这个: var attributes = new CTStringAttributes() { }; var paragraphStyleSettings = new CTParagraphStyleSettings() { Alignment = CTTextAlignment.Center }; attributes.Paragrap

我有一个包含属性文本的UITextView。 我正在尝试将其居中(因为文本具有属性,textView.TextAlignment不起作用)

我该怎么办? 我试过这个:

var attributes = new CTStringAttributes() { };
var paragraphStyleSettings = new CTParagraphStyleSettings() { Alignment = CTTextAlignment.Center };
attributes.ParagraphStyle = new CTParagraphStyle(paragraphStyleSettings);
textView.AttributedText = attributedString;
但是我遇到了以下崩溃:
Foundation.monotuchException-NSInvalidArgumentException[NSCFType textBlocks]:无法识别的选择器发送到实例…


所以我想这不是使用CTParagraphStyleSettings的正确方式?但是我找不到任何使用Xamarin语法的例子。。。如何设置文本的水平对齐?

在Swift中,您将使用UIKit类而不是CoreText:

    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = .center
    let attributes = [NSParagraphStyleAttributeName: paragraphStyle, NSForegroundColorAttributeName : UIColor.gray, NSFontAttributeName : UIFont(name: "Helvetica", size: 18)!]
    let attributedString = NSAttributedString(string: "some text", attributes: attributes)

我不是Xamarin程序员,我的c#已经生锈了,但Xamarin有这个功能。

谢谢!如果有人在寻找相同的东西,在Xamarin语法中:
var attributes=new-UIStringAttributes(){};var paragraphStyle=新的NSMutableParagraphStyle(){};paragraphStyle.Alignment=UITextAlignment.Center;attributes.ParagraphStyle=段落样式