我将 UIView
子类化为条形图(制作条形图),如何对我的 FirstBarView
的大小属性进行硬编码?我收到错误:
FirstBarView type does not have a member named frame?
import UIKit
@IBDesignable class FirstBarView: UIView {
@IBInspectable var FirstBarViewColor: UIColor = UIColor.orangeColor()
override func drawRect(rect: CGRect) {
FirstBarView.frame = CGRectMake(50, 200, 20, 400)
}
}
最佳答案
使用 self
而不是 FirstBarView
。
您正在刷新类而不是类的实例。
@IBDesignable class FirstBarView: UIView {
@IBInspectable var FirstBarViewColor: UIColor = UIColor.orangeColor()
override func drawRect(rect: CGRect) {
self.frame = CGRectMake(50, 200, 20, 400)
}
}
//To create a new class with a rect.
var myFirstBarView = FirstBarView()
myFirstBarView.drawRect(CGRectMake(0,0,200,50))
关于ios - 如何在 Swift 中硬编码 UIView 的大小属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30200273/