Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIActivityIndicatorView忽略颜色属性_Ios - Fatal编程技术网

Ios UIActivityIndicatorView忽略颜色属性

Ios UIActivityIndicatorView忽略颜色属性,ios,Ios,以下是我初始化UIActivityAndictOrView的代码: self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge]; self.indicator.color = [UIColor colorWithRed:252.0 green:113.0 blue:9.0 alpha:1.0]; s

以下是我初始化UIActivityAndictOrView的代码:

self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
    self.indicator.color = [UIColor colorWithRed:252.0 green:113.0 blue:9.0 alpha:1.0];
    self.indicator.center = self.view.center;
    [self.view addSubview:self.indicator];

动画开始后-指示器显示在适当的位置,但为白色。为什么忽略颜色属性?

值在0和1之间浮动。试试这个:

    self.indicator.color = [UIColor colorWithRed:252.0/255.0 green:113.0/255.0 blue:9.0/255.0 alpha:1.0];

我很惊讶选择的答案在2015年12月起作用,因为无论我在iOS 9.2中做什么,我都无法让颜色显示除白色以外的任何东西。这适用于大型白色旋转器

我发现有效的方法是以0的alpha值启动控件,然后在100毫秒后更改颜色并显示它。下面的代码来自github上的ATMHud fork:

- (void)setActivity:(BOOL)activity
{
    hudView.showActivity = activity;
    if (activity) {
        [hudView.activity startAnimating];
        hudView.activity.alpha = 0;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^
            {
                // Workaround for bug where Apple ignores the color property
                [self changeColor];
            } );
    } else {
        [hudView.activity stopAnimating];
    }
}
- (void)changeColor
{
    hudView.activity.color = [UIColor blackColor];
    [UIView animateWithDuration:.250+_animateDuration animations: ^{ hudView.activity.alpha = 1; }];
}

需要注意的是,
activityIndicatorViewStyle
将覆盖
color
属性,如下所示:

如果为活动指示器设置颜色,它将覆盖activityIndicatorViewStyle属性提供的颜色

因此,您只需先设置样式,然后设置颜色:

let activityIndicator = UIActivityIndicatorView()
activityIndicator.activityIndicatorViewStyle = .whiteLarge
let myColor = UIColor.colorWithRed(252.0/255.0, green: 113.0/255.0, blue: 9.0/255.0, alpha: 1.0)
activityIndicator.color = myColor
activityIndicator.startAnimating()

应该是这样。

@ааааааааааааааааааа107