0
此代碼有什麼問題?我在不同的類中創建了變量,它們是RGB顏色的隨機值。使用不同類別的變量在Xcode上快速創建顏色時遇到問題
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沒有一個成員叫紅」
調用顏色你不能只用變量來自不同的類沒有得到這個類的一個實例,並從該實例讓他們。此外,你應該用大寫字母開始你的類名。 – rdelmar
我該怎麼做?我沒有太多經驗。 – Steve