Xamarin.iOS 中的多文本粗体 UITextView

Multiple Text bold UITextView in Xamarin.iOS

我需要加粗文本。段落和标题的种类。

示例: Xamarin.iOS UITextView 一些文本 粗体 和一些文本 header

在上面的例子中,我需要在Textview中设置粗体和Header粗体。

请帮忙。

您可以在代码中实现它,我知道您已经找到了答案 here

另一种方式:可以直接在故事板中设置属性字符串,更简单直观。

首先将文字样式设置为Attributed,select文字,然后在属性菜单中点击字体,可以为所有headers设置粗体和字体大小,参考here.


但是,我在 Visual Studio for macVisual Studio for windows 中进行了测试。

此功能适用于第一个功能,但在 visual studio for windows 中不受支持。

所以你只能在vs for mac.

我已经使用 HTML 字符串设置粗体,因为我在我的应用程序中进行了本地化。

public NSAttributedString ConvertBoldTextUsingHtml(string htmlString)
{
   var err = new NSError();
   var atts = new NSAttributedStringDocumentAttributes
   {
        DocumentType = NSDocumentType.HTML,
        StringEncoding = NSStringEncoding.UTF8
    };
   return new NSAttributedString(NSData.FromString(htmlString), atts, ref err);
}
textView.AttributedText= ConvertBoldTextUsingHtml(htmlString)