Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 636 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adjust alpha of UIColor

#1
I set a `UIColor` using rgb to a background of a `UILabel`. I'm trying to adjust the `alpha` only. How can I modify the alpha of an existing rgb `UIColor`?

**Edit**

Basically I have `UILabels` that have a set `UIColor` (using rgb), and I won't know what color the `UILabels` are. At a certain point, I will have to change the `labels` alpha`. How can I just change the labels color alpha?
Reply

#2
Please set alpha in below code -

[UIColor colorWithRed:200.0/255.0 green:191.0/255.0 blue:231.0 /255.0 alpha:1.0]
Reply

#3
why not using `label.alpha = 0.5` ? to adjust your label's alpha?

update: if you want to adjust alpha from a old color, here is an example:

UIColor uicolor = [UIColor greenColor];
CGColorRef color = [uicolor CGColor];

int numComponents = CGColorGetNumberOfComponents(color);

UIColor newColor;
if (numComponents == 4)
{
const CGFloat *components = CGColorGetComponents(color);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
newColor = [UIColor colorWithRed: red green: green blue: blue alpha: YOURNEWALPHA];

}
Reply

#4
If you have custom colors defined, you can do this as well:

view.backgroundColor = [[MyClass someColor] colorWithAlphaComponent:0.25];
Reply

#5
`colorWithAlphaComponent:` did the trick.

So what I had to do was:

self.mylabel.backgroundColor = [self.myLabel.backgroundColor colorWithAlphaComponent:0.3];
Reply

#6
**Swift 3+**

yourUIView.backgroundColor = UIColor.white.withAlphaComponent(0.75)

**Swift 2**

yourUIView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.75)
Reply

#7
Version **Swift (5.4)**

UIColor.blue.withAlphaComponent(0.5)
Reply

#8
The shortest possible code (**Swift 5**):

view.backgroundColor = .black.withAlphaComponent(0.75)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through