Display activity indicator inside UIButton

后端 未结 10 1725
囚心锁ツ
囚心锁ツ 2021-01-31 17:36

I would like to change the content of a UIButton to an ActivityIndicator after it is pressed.

I know buttons have an imageView and a titleLabel, but I don\'t know how to

10条回答
  •  余生分开走
    2021-01-31 17:54

    Excellent @Steve,

    Can use below implementation instead of line,

    var activityIndicator: UIActivityIndicatorView!

    use this, so that if we configure the activity indicator before calling showLoading(), the app wont crash.

    private var _activityIndicator:UIActivityIndicatorView! = nil
    var activityIndicator: UIActivityIndicatorView{
        set{
            _activityIndicator = newValue
    
        }
        get{
            if _activityIndicator == nil{
                _activityIndicator = createActivityIndicator()
            }
            return _activityIndicator
        }
    }
    

提交回复
热议问题