我有一个 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/