Xamarin Mac 中 AttributeName 的用途 [英] What to use for AttributeName in Xamarin Mac

查看:12
本文介绍了Xamarin Mac 中 AttributeName 的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Xamarin 中为我的 NSMutableAttributedString 中的子字符串着色,但它似乎缺少正确的常量,

I'm trying to colorize a substring in my NSMutableAttributedString in Xamarin, but it seems to be missing the proper constants,

我应该在那里放什么?

更新.这越来越近了:

var s = new NSMutableAttributedString ("hello");
s.AddAttribute (CTStringAttributeKey.ForegroundColor , NSColor.Red, new NSRange (0, 3));
wordLabel.AttributedStringValue = s;

并给予

虽然屏幕上的颜色仍然是黑色文本!

though the color on screen is still black text!

Update2 也许 CTStringAttributeKey 是错误的,但没有 NSStringAttributeKey

Update2 Maybe CTStringAttributeKey is the wrong one, but there is no NSStringAttributeKey

推荐答案

好的,所以我查看了 API,它似乎就在那里,就在 NSAttributedString

Ok, so I looked at the API and it seems it's there, just under NSAttributedString

ForegroundColorAttributeName

所以使用类似的东西:

s.AddAttribute(NSAttributedString.ForegroundColorAttributeName, NSColor.Red, new NSRange(0,3));

这篇关于Xamarin Mac 中 AttributeName 的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆