cgcolor

UIButton Borders Function Only Gives Back White Borders

故事扮演 提交于 2019-12-24 01:47:29
问题 I'm trying to create a Button Borders Function in Swift to help style my UI. However whatever RGB values I pass in/initialize the function only creates white borders. Here is my function: func buttonsWithBorders(button: UIButton, borderWidth: CGFloat, redcolour: CGFloat , greencolour: CGFloat, bluecolour: CGFloat, alpha: CGFloat?) { let redcolour : CGFloat = 7.0 var greencolour : CGFloat = 3.0 var bluecolour : CGFloat = 2.0 var alpha: CGFloat = 1.0 var widthOfBorder: CGFloat = borderWidth var

Using UIColor with CAShapeLayer

可紊 提交于 2019-12-14 03:36:48
问题 I'm passing an RGB color to shapeLayer.fillColor and shapeLayer.strokeColor , and my code is crashing. Here's what I tried: let shapeLayer = CAShapeLayer() shapeLayer.fillColor = (UIColor(red: 57, green: 65, blue: 101, alpha: 1) as! CGColor) shapeLayer.strokeColor = (UIColor(red: 57, green: 65, blue: 101, alpha: 1) as! CGColor) If I write my RGB color as: UIColor(red: 57, green: 65, blue: 101, alpha: 1) Xcode gives me a warning to change it to: (UIColor(red: 57, green: 65, blue: 101, alpha: 1

Swift 3 unresolved identifier CGColorGetComponents [duplicate]

给你一囗甜甜゛ 提交于 2019-12-11 07:29:56
问题 This question already has answers here : Xcode 8 Beta 4 CGColor.components unavailable (5 answers) Closed 3 years ago . How can I refactor this code in Swift 3?: extension UIColor { var hexString: String { // Produces "Use of unresolved identifier 'CGColorGetComponents'" let components = CGColorGetComponents(self.cgColor) .... } } 回答1: var r:CGFloat = 0, g:CGFloat = 0, b:CGFloat = 0, a:CGFloat = 0 self.getRed(&r, green: &g, blue: &b:, alpha: &a) ... 来源: https://stackoverflow.com/questions

Casting from AnyObject to CGColor? without errors or warnings

◇◆丶佛笑我妖孽 提交于 2019-12-08 19:34:17
问题 Hello StackOverflow :) I've been running into a weird problem since I upgraded to swift 2.0 I'm trying to set a border color, so I'm writing self.layer.borderColor = borderColor as! CGColor where borderColor is an AnyObject , while self.layer.borderColor is a CGColor? If I write self.layer.borderColor = borderColor as! CGColor I get the warning Treating a forced downcast to 'CGColor' as optional will never produce 'nil' and is recommended to instead use as? If I instead write self.layer

How to set two colors in UIButton background

▼魔方 西西 提交于 2019-12-07 17:23:11
问题 I want to set two different colors in UIButton background. I know how to set one color or border and etc. But I don't know how to set two different colors in the background. I show the example. I use Swift 2 回答1: You can use a gradient with 2 pair of repeating colours: let gradient: CAGradientLayer = CAGradientLayer() gradient.frame = button.bounds gradient.colors = [ UIColor.greenColor().CGColor, UIColor.greenColor().CGColor, UIColor.blackColor().CGColor, UIColor.blackColor().CGColor ] /*

Manually color fading from one UIColor to another

♀尐吖头ヾ 提交于 2019-12-06 23:51:23
问题 I'm trying to fade one UIColor to another in a drawRect . I've created this function to calculate a color at a certain percentage: - (UIColor *)colorFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor percent:(float)percent { float dec = percent / 100.f; CGFloat fRed, fBlue, fGreen, fAlpha; CGFloat tRed, tBlue, tGreen, tAlpha; CGFloat red, green, blue, alpha; if(CGColorGetNumberOfComponents(fromColor.CGColor) == 2) { [fromColor getWhite:&fRed alpha:&fAlpha]; fGreen = fRed; fBlue = fRed;

How to set two colors in UIButton background

怎甘沉沦 提交于 2019-12-06 00:08:36
I want to set two different colors in UIButton background. I know how to set one color or border and etc. But I don't know how to set two different colors in the background. I show the example. I use Swift 2 You can use a gradient with 2 pair of repeating colours: let gradient: CAGradientLayer = CAGradientLayer() gradient.frame = button.bounds gradient.colors = [ UIColor.greenColor().CGColor, UIColor.greenColor().CGColor, UIColor.blackColor().CGColor, UIColor.blackColor().CGColor ] /* repeat the central location to have solid colors */ gradient.locations = [0, 0.5, 0.5, 1.0] /* make it

What does CGColorGetComponents() return?

允我心安 提交于 2019-12-05 23:23:02
问题 CGFloat* colors = CGColorGetComponents(hsbaColor.CGColor); Does this return a float, or an array of floats? It looks like the asterisk is shorthand for creating an array. Is that correct? When I call this function on the CGColor property of an HSB UIColor object does it convert the values to RGB? 回答1: Yes, it returns an array of CGFloats . Specifically, it returns "an array of intensity values for the color components (including alpha) associated with the specified color." The color

Manually color fading from one UIColor to another

房东的猫 提交于 2019-12-05 03:45:15
I'm trying to fade one UIColor to another in a drawRect . I've created this function to calculate a color at a certain percentage: - (UIColor *)colorFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor percent:(float)percent { float dec = percent / 100.f; CGFloat fRed, fBlue, fGreen, fAlpha; CGFloat tRed, tBlue, tGreen, tAlpha; CGFloat red, green, blue, alpha; if(CGColorGetNumberOfComponents(fromColor.CGColor) == 2) { [fromColor getWhite:&fRed alpha:&fAlpha]; fGreen = fRed; fBlue = fRed; } else { [fromColor getRed:&fRed green:&fGreen blue:&fBlue alpha:&fAlpha]; } if

What does CGColorGetComponents() return?

梦想与她 提交于 2019-12-04 03:11:30
CGFloat* colors = CGColorGetComponents(hsbaColor.CGColor); Does this return a float, or an array of floats? It looks like the asterisk is shorthand for creating an array. Is that correct? When I call this function on the CGColor property of an HSB UIColor object does it convert the values to RGB? hbw Yes, it returns an array of CGFloats . Specifically, it returns "an array of intensity values for the color components (including alpha) associated with the specified color." The color components returned depend on what color space the passed CGColorRef uses. More information can be found in the