uicolor

Converting from UIExtendedSRGBColorSpace to Hex

别来无恙 提交于 2021-01-29 09:17:37
问题 I'm using a framework that outputs colour in the UIExtendedSRGBColorSpace format. I need to display a six character hex value for this output colour to the user and for a backend application that only accepts six-character hex codes. I've tried numerous conversion methods but they all seem to result in odd hex values. For example, getting an output UIExtendedSRGBColorSpace 0.276088 -0.0525 1.05 1 and using an extension like this (which i've used successfully many times before) results in

How to change UIScrollView Indicator color?

萝らか妹 提交于 2021-01-27 21:06:25
问题 When I use UIColor.blue its changing, but when I try to apply RGB, its not reflected in scrollview indicator. func scrollViewDidScroll(_ scrollView: UIScrollView) { let verticalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as! UIImageView) verticalIndicator.backgroundColor = UIColor(red: 211/255, green: 138/255, blue: 252/255, alpha: 1) // verticalIndicator.backgroundColor = UIColor.blue } 回答1: I think problem is here verticalIndicator.backgroundColor =

How to correctly get and set UIColor for UIView?

寵の児 提交于 2021-01-27 13:18:14
问题 I'm trying to change a UIView 's backgroundColor based on its current color. E.g. say MyView is now red, on touch I want to make it blue and vice versa. But I noticed I cannot get the correct name of the UIColor to check the current color. As an example, if I do: if MyView.backgroundColor == .systemRed { print("Red") } else { print("Not red") } This will always print "Not red", even if I explicitly set MyView.backgroundColor = .systemRed When I check the color being used: print("Color = \

Get lighter and darker color variations for a given UIColor

会有一股神秘感。 提交于 2020-08-20 17:58:11
问题 How to get different lighter and darker variations of a given UIColor in Swift? 回答1: Updated Use below UIColor Extension: extension UIColor { func lighter(by percentage: CGFloat = 30.0) -> UIColor? { return self.adjust(by: abs(percentage) ) } func darker(by percentage: CGFloat = 30.0) -> UIColor? { return self.adjust(by: -1 * abs(percentage) ) } func adjust(by percentage: CGFloat = 30.0) -> UIColor? { var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0 if self

Add a gradient on UIImageView

徘徊边缘 提交于 2020-07-28 13:04:26
问题 I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of this marty like: transparent (top) to black (bottom). Thanks for the help :) Here is my code in Swift 3. This part is fine : import UIKit class ViewController: UIViewController { @IBOutlet weak var shanghaiImage: UIImageView! // beginning index var

Add a gradient on UIImageView

落爺英雄遲暮 提交于 2020-07-28 13:04:22
问题 I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of this marty like: transparent (top) to black (bottom). Thanks for the help :) Here is my code in Swift 3. This part is fine : import UIKit class ViewController: UIViewController { @IBOutlet weak var shanghaiImage: UIImageView! // beginning index var

How to convert UIColor to string and string to UIColor using swift?

社会主义新天地 提交于 2020-07-05 09:11:15
问题 I have an object with a UIColor property: class Beer: NSObject { var color: UIColor? ... } I'm saving this to a DB, so I need to make this property into a valid JSON type, so I'm thinking of converting it to a string. How can I convert into a string to store, and then when loading using that string to create the UIColor? 回答1: I have put some sample for both conversion, still you can find many code for the conversion For the conversion from UIColor to hex string you can use the following code: