这段代码有什么问题?我在不同的类中创建了变量,这些变量是RGB颜色的随机值。
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
}
*/
}
}
这些是错误消息:
“graphics.type没有名为red的成员”
“呼叫中的额外参数'绿色'”
答案 0 :(得分:1)
创建包含颜色变量的另一个类的实例
var colors = ColorClass()
调用该实例的颜色
colors.green