Ios NSMutableAttributedString是否未追加?
我试图用以下值附加两个NSAttributedString,得到的是第一个Ios NSMutableAttributedString是否未追加?,ios,uitableview,xamarin.ios,nsattributedstring,nsmutableattributedstring,Ios,Uitableview,Xamarin.ios,Nsattributedstring,Nsmutableattributedstring,我试图用以下值附加两个NSAttributedString,得到的是第一个NSAttributedString,但不是第二个。标签位于UITableView中。我不知道是什么导致了这个问题 NSMutableAttributedString ms=新的NSMutableAttributedString(); NSAttributedString attributedString=新NSAttributedString(“添加新卖家”,新UIStringAttributes()){ Font=UI
NSAttributedString
,但不是第二个。标签位于UITableView
中。我不知道是什么导致了这个问题
NSMutableAttributedString ms=新的NSMutableAttributedString();
NSAttributedString attributedString=新NSAttributedString(“添加新卖家”,新UIStringAttributes()){
Font=UIFont.FromName(“流沙规则”,17)});
NSAttributedString attributedString1=新NSAttributedString(“+”,新UIStringAttributes(){
Font=UIFont.FromName(“常规流沙”,17),
ForegroundColor=新UIColor(33f、201f、130f、1f)};
ms.Append(attributedString);
ms.Append(attributedString1);
cell.seller.attributeText=ms;
您的第二个NSAttributedString
追加在最后的NSMutableAttributedString
中,但您可能看不到它,因为它是白色的。您在评论中指出的@Larme问题与您创建UIColor的方式有关
UIColor
接受介于0和1之间的nfloat
值。当您说newuicolor(33f、201f、130f、1f)
生成的颜色将是白色,因为它会将超过1.0的任何值视为1.0,因此
新UIColor(33f、201f、130f、1f)
的结果与新UIColor(1f、1f、1f、1f)
相同
要修复代码,只需将UIColor初始化更改为
新UIColor(33f/255、201f/255、130f/255、1f)
如您所见,将3个颜色值(RGB)除以255。最后一个值表示alpha
希望这有帮助。-注意UIColor()
应该期望值介于0和1之间,所以33/255f
?那么一个呢?您能在附加attributedString1
之前/之后打印ms
以检查它是否真的设置好了吗?