As can be seen in the code below, the color of activity indicator is assigned based on the platform. For iOS this is .Gray. I'd really like to use the .WhiteLarge option as I'm working with a dark background color before the image loads. Unfortunately, this option cannot be set. This would be a nice feature to have.
set {
if kf_showIndicatorWhenLoading == newValue {
return
} else {
if newValue {
#if os(OSX)
let indicator = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
indicator.controlSize = .SmallControlSize
indicator.style = .SpinningStyle
#else
#if os(tvOS)
let indicatorStyle = UIActivityIndicatorViewStyle.White
#else
let indicatorStyle = UIActivityIndicatorViewStyle.Gray
#endif
let indicator = UIActivityIndicatorView(activityIndicatorStyle:indicatorStyle)
indicator.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleBottomMargin, .FlexibleTopMargin]
Hi, @kbpontius
I guess you could get the indicator view by accessing imageView.kf_indicator and then set it there. Does it work for you?
Good suggestion, I'll give it a shot. Thanks!
For the record, here's how you can set it with kf.indicator:
(imageView.kf.indicator?.view as? UIActivityIndicatorView)?.color = .white
I don't really like all those ? but I think that's the best way to do it.
Another solution would be to add an associated value to .activity but it would break existing projects.
public enum IndicatorType {
/// No indicator.
case none
/// Use system activity indicator.
case activity(let color: UIColor?) // Too bad we cannot set its default value to nil
/// Use an image as indicator. GIF is supported.
case image(imageData: Data)
/// Use a custom indicator, which conforms to the `Indicator` protocol.
case custom(indicator: Indicator)
}
Existing projects would have to change .kf.indicatorType = .activity to .kf.indicatorType = .activity(color: nil).
Most helpful comment
For the record, here's how you can set it with
kf.indicator:I don't really like all those
?but I think that's the best way to do it.Another solution would be to add an associated value to
.activitybut it would break existing projects.Existing projects would have to change
.kf.indicatorType = .activityto.kf.indicatorType = .activity(color: nil).