Xamarin.iOS – Setting UILabel Colors with C# and UIColor

In this lesson

  • Use default colors of UIColor
  • Set background color of UILabel
  • Set text color of UILabel
  • Create custom color from UIColor

Transcript

Tap on time to skip ahead

00:00

Now one of the things we can do here is we can say helloLabel.BackgroundColor = UIColor.Green. What UIColor is something that Apple has given developers to make things easier for them because developers just don’t care what shade of orange, they just want orange. There’s this static class called UIColor where I can just reference things. You’ll notice that I didn’t have to type in new UIColor, I can just say UIColor.Red or green or whatever. That’s a case of the static property on the class.

00:44

Now when we run this, we can see our background color is green. HelloLabel.TextColor = UIColor.White.

01:04

Now let’s say you have a designer that wants a really custom color. Another handy function of UIColor is UIColor.FromRGB. Let’s say I want this to be Red, I can then say (255, 0,0), like so.