我有这个类,我添加了一个名为GradientDirection的枚举,我想在开始时用一个值初始化它,我怎么能像使用colors变量那样做呢?
enum GradientDirection {
case Horizontal
case Vertical
}
class GradientColorView : UIView {
var colors : NSArray = NSArray() {
didSet {
setNeedsDisplay()
}
}
var direction : GradientDirection. {
didSet {
setNeedsDisplay()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func drawRect(rect: CGRect) {
var topRect : CGRect = CGRectMake(0, 0, rect.size.width, rect.size.height / 2.0)
var firstColor : UIColor = self.colors[0] as! UIColor
firstColor.setFill()
UIRectFill(topRect)
var bottomRect : CGRect = CGRectMake(0, rect.size.height/2.0, rect.size.width, rect.size.height/2.0)
var secondColor : UIColor = self.colors[1] as! UIColor
secondColor.setFill()
UIRectFill(bottomRect)
}
}
提前致谢!