我正在尝试使用以下值附加两个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}}
答案 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。
希望这会有所帮助.-