无法为UIActivityIndi​​catorView设置指示器样式

时间:2016-11-04 08:41:03

标签: ios swift uiactivityindicatorview

我正试图像这样初始化fab

UIActivityIndicatorView

它存在于自定义var indicatorStyle: UIActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.white lazy fileprivate var loadingActivityIndicator: UIActivityIndicatorView = { let indicator = UIActivityIndicatorView(activityIndicatorStyle: indicatorStyle) indicator.hidesWhenStopped = false return indicator }() 中。我将样式设置为UIButton,因此可以在init之前设置颜色。但是我收到了错误:

var我在这里做错了什么?

3 个答案:

答案 0 :(得分:0)

您可以在构造函数中设置样式。你可以尝试这个,它对我有用:

lazy var activityIndicator: UIActivityIndicatorView = {
        var ai = UIActivityIndicatorView()
        ai = UIActivityIndicatorView(activityIndicatorStyle: .white)
        ai.hidesWhenStopped = false
        return ai
    }()

答案 1 :(得分:0)

成员变量indicatorStyle不能用于像这样声明的其他成员变量

let  indicatorStyle: UIActivityIndicatorViewStyle = .White
let  indicator : UIActivityIndicatorView =   UIActivityIndicatorView(activityIndicatorStyle: indicatorStyle)

并在一个很好的函数中使用它

func  test() -> Void {
     let  indicatorStyle: UIActivityIndicatorViewStyle = .White
     let  indicator : UIActivityIndicatorView =    UIActivityIndicatorView(activityIndicatorStyle: indicatorStyle)

}

答案 2 :(得分:0)

它必须是var indicatorStyle:UIActivityIndicatorViewStyle = .white private lazy var loadingActivityIndicator: UIActivityIndicatorView = { let indicator = UIActivityIndicatorView(activityIndicatorStyle: self.indicatorStyle) indicator.hidesWhenStopped = false return indicator }() 在像这样的惰性块中

>>> import datetime

>>> my_date = '20-Apr-53'
>>> d = datetime.datetime.strptime(my_date, '%d-%b-%y')
>>> d
datetime.datetime(2053, 4, 20, 0, 0)
#                   ^ year = 2053  
>>> if d.year > 2000:
...     d = d.replace(year=d.year-100)  # subtract year by 100
... 
>>> d
datetime.datetime(1953, 4, 20, 0, 0)
#                   ^ year = 1953
>>> d.strftime('%Y-%m-%d') # %Y instead of %y, reason mentioned below
'1953-04-20'
#  ^ all four digit of year