Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to use for AttributeName in Xamarin Mac

Tags:

c#

xamarin

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

enter image description here

What should I put there?

Update. This gets closer:

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

and gives

enter image description here

though the color on screen is still black text!

enter image description here

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

enter image description here

like image 323
tofutim Avatar asked Mar 28 '14 18:03

tofutim


People also ask

How do I run Xamarin forms on Mac?

In Visual Studio for Mac, right-click on the existing Xamarin. Forms solution and choose Add > Add New Project... In the New Project window choose Mac > App > Cocoa App and press Next. Type an App Name (and optionally choose a different name for the Dock Item), then press Next.

Can you use Xamarin on Mac?

With Xamarin. Forms, you can use C# or XAML to build cross-platform user interfaces for iOS, Android, and macOS.

What is Xamarin on Mac?

What is Xamarin on Mac? You can think of Xamarin as an open-source platform for building applications. You can create cross-platform applications for Windows, Android, iOS using. NET.


1 Answers

In case people are wondering what the equivalent is for Xamarin iOS, here it is: The foreground color attribute name can be found here: UIStringAttributeKey.ForegroundColor

Also NSColor.Red should be UIColor.Red

So adding an attribute should look like:

s.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Red, new NSRange(0,3));
like image 186
Mike Richards Avatar answered Oct 01 '22 06:10

Mike Richards