gpt4 book ai didi

xamarin.ios - 如何对齐 AttributedText ?

转载 作者:行者123 更新时间:2023-12-01 11:22:53 25 4
gpt4 key购买 nike

我有一个包含属性文本的 UITextView。我试图将它居中(因为文本是属性的,textView.TextAlignment 不起作用)。

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

var attributes = new CTStringAttributes() { };
var paragraphStyleSettings = new CTParagraphStyleSettings() { Alignment = CTTextAlignment.Center };
attributes.ParagraphStyle = new CTParagraphStyle(paragraphStyleSettings);
textView.AttributedText = attributedString;

但我遇到以下崩溃:Foundation.MonoTouchException - NSInvalidArgumentException [NSCFType textBlocks]: unrecognized selector sent to instance ... enter image description here

所以我想这不是应该使用 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 有 equivalent functions .

关于xamarin.ios - 如何对齐 AttributedText ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40265231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com