c# - 如何格式化单元格文本标签的某些单词

标签 c# ios swift xamarin fonts

我有一个 xamarin iOS 项目,我在其中显示一个包含 x 行文本的单元格。我目前这样定义我的单元格:

public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        UITableViewCell cell = tableView.DequeueReusableCell ("cells");
        ...
        cell.TextLabel.Lines = 0;
        cell.TextLabel.Text = "Bold: " + info1 + "Bold: " + info2;

        ...
    }

显示单元格如下:

   +----------------------+
   |Bold: Testing         |
   |Bold: Testing2        |
   +----------------------+

我希望能够仅将 Bold 文本转换为粗体,而将其他信息保留为普通文本字体。考虑到我目前的方法,这可能吗?

最佳答案

你可以这样做:

let attributedText = NSMutableAttributedString(string: "YOUR FIRST TEXT STRING", attributes: [NSFontAttributeName: UIFont.boldSystemFontOfSize(20.0), NSForegroundColorAttributeName: UIColor.redColor()])
let anotherString = NSAttributedString(string: "YOUR SECOND TEXT STRING", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(20.0), NSForegroundColorAttributeName: UIColor.blueColor()])
attributedText.appendAttributedString(anotherString)
cell.TextLabel.AttributedText = attributedText

您可以更改字体大小和颜色。

关于c# - 如何格式化单元格文本标签的某些单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37977112/

相关文章:

objective-c - 防止 Obj-C 框架类命名与 Swift 中的 NSUnit 冲突

ios - Swift:编辑模式,将 editButtonItem() 链接到 IBAction

c# - XAudio2 - 使用动态缓冲区时破解输出

ios - GCD、NSThread 或 NSOperationQueue 哪个最好?

c# - PrincipalContext LDAPS 自签名证书

ios - 从 UIImage 创建 CGPath

ios - Titanium ,验证名称包含 -> & 的 iOS 应用程序

swift - 以编程方式按钮自动布局?

c# - 扩展方法和接口(interface)

C# XNA - 遍历项目并绘制它们