Reputation: 1229
So, my code works fine when I do something like this:
let label = UILabelBuiler("1", backgroundColor: UIColor.redColor(), textColor: UIColor.whiteColor(), font: UIFont(name: "FuturaStd-Heavy", size: 11)!)
But it does nothing when I do this:
let label = UILabelBuiler("1", backgroundColor: UIColor(red: 255, green: 75, blue: 75, alpha: 1), textColor: UIColor(red: 185, green: 200, blue: 202, alpha: 1), font: UIFont(name: "FuturaStd-Heavy", size: 11)!)
Here is what it looks like when I use the first one:
and here is the second one (that doesn't show up)
And my UILabelBuilder function looks like this:
func UILabelBuiler(labelText: String, backgroundColor: UIColor, textColor: UIColor, font: UIFont) -> UILabel {
let label = UILabel(frame: CGRectMake(218, 14, 15, 20))
label.text = labelText
label.numberOfLines = 0
label.sizeToFit()
label.backgroundColor = backgroundColor
label.textColor = textColor
label.font = font
return label
}
Additionally, does anyone know off the top of their head how I could round the label's background?
Upvotes: 1
Views: 1239
Reputation: 285260
The color components of UIColor
are defined as
The {red, green, blue, alpha} component of the color object, specified as a value from 0.0 to 1.0.
Adjust the values accordingly or divide each of them by 255.0
Upvotes: 2
Reputation: 13296
When creating a color, the rgba values it expects are floats in the range 0...1
so you can either enter the colors as floats or by dividing by 255
UIColor(red: 1.0, green: 0.29, blue: 0.29, alpha: 1.0)
UIColor(red: 255.0 / 255.0, green: 75.0 / 255.0, blue: 75.0 / 255.0, alpha: 1.0)
Upvotes: 1