NSMutableAttributedString没有附加?

时间:2018-03-24 18:21:37

标签: ios uitableview xamarin.ios nsattributedstring nsmutableattributedstring

我正在尝试使用以下值附加两个NSAttributedString,我得到第一个NSAttributedString但不是第二个UITableView。标签位于NSMutableAttributedString ms = new NSMutableAttributedString(); NSAttributedString attributedString = new NSAttributedString("Add New Seller ", new UIStringAttributes(){ Font = UIFont.FromName("Quicksand-Regular", 17)}); NSAttributedString attributedString1 = new NSAttributedString("+", new UIStringAttributes(){ Font = UIFont.FromName("Quicksand-Regular", 17), ForegroundColor = new UIColor(33f, 201f, 130f, 1f)}); ms.Append(attributedString); ms.Append(attributedString1); cell.seller.AttributedText = ms; 内。我不知道造成这个问题的原因。

{{1}}

1 个答案:

答案 0 :(得分:0)

您的第二个NSAttributedString会附加在最终的NSMutableAttributedString中,但您可能看不到它,因为它是白色的。您在评论中指出的@Larme问题与您创建UIColor的方式有关。

UIColor接受介于0和1之间的nfloat值。当您说new UIColor(33f, 201f, 130f, 1f)时,生成的颜色将为白色,因为它会将1.0以上的任何值视为1.0,因此

new UIColor(33f, 201f, 130f, 1f)new UIColor(1f, 1f, 1f, 1f)的结果相同。

要修复代码,只需将UIColor初始化更改为

即可

new UIColor(33f/255, 201f/255, 130f/255, 1f)

正如您所看到的将颜色(RGB)的3个值除以255.最后一个值代表alpha。

希望这会有所帮助.-