Steve
Steve

Reputation: 1153

Trouble creating a color in swift on Xcode using variables in a different class

What is wrong with this code? I created variables in a different class that are random values for an RGB color.

import UIKit

class graphics: ViewController {

    class color: UIView
    {
    override func drawRect(rect: CGRect)
    {
        let swiftColor = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1);

        let context = UIGraphicsGetCurrentContext()
        CGContextSetLineWidth(context, 5.0)
        CGContextSetStrokeColorWithColor(context,
            UIColor(red: red1, green: green1, blue: blue1, alpha: 1.0))//.blueColor().CGColor)
        let rectangle = CGRectMake(60,170,200,80)
        CGContextAddRect(context, rectangle)
        CGContextStrokePath(context)
        CGContextSetFillColorWithColor(context,
            UIColor(red: red, green: green, blue: blue, alpha: 1.0))//.redColor().CGColor)
            CGContextFillRect(context, rectangle)
    }
        /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    }

}

these are the error messages:

"graphics.type does not have a member named red"

"extra argument 'green' in call"

Upvotes: 0

Views: 178

Answers (1)

sophie f
sophie f

Reputation: 499

  1. Create an instance of the other class that contains your color variables

    var colors = ColorClass()
    
  2. Call the colors from that instance

    colors.green  
    

Upvotes: 1

Related Questions