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

我该放什么?
更新.这更接近:
var s = new NSMutableAttributedString ("hello");
s.AddAttribute (CTStringAttributeKey.ForegroundColor , NSColor.Red, new NSRange (0, 3));
wordLabel.AttributedStringValue = s;
Run Code Online (Sandbox Code Playgroud)
并给出

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

Update2可能CTStringAttributeKey是错误的,但没有NSStringAttributeKey

Mik*_*rds 14
如果人们想知道Xamarin iOS的等价物是什么,这里是:前景颜色属性名称可以在这里找到:UIStringAttributeKey.ForegroundColor
也NSColor.Red应该是UIColor.Red
因此,添加属性应如下所示:
s.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Red, new NSRange(0,3));
Run Code Online (Sandbox Code Playgroud)
好的,所以我查看了API,它似乎就在那里,就在下面 NSAttributedString
所以使用类似的东西:
s.AddAttribute(NSAttributedString.ForegroundColorAttributeName, NSColor.Red, new NSRange(0,3));
Run Code Online (Sandbox Code Playgroud)
小智 6
重要:
Xamarin.Mac中的键已从此更改NSAttributedString为NSStringAttributeKey:
s.AddAttribute(NSAttributedString.ForegroundColorAttributeName, NSColor.Red, new NSRange(0,3));
Run Code Online (Sandbox Code Playgroud)
应该:
s.AddAttribute(NSStringAttributeKey.ForegroundColorAttributeName, NSColor.Red, new NSRange(0,3));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |