如何改变灰色的颜色

Nim*_*ekh 6 iphone xcode cocoa-touch

我的问题是"如何改变HUD的颜色代替灰色"

  • 在hud中,它们是一种灰色的颜色.
  • 如何更改该颜色的颜色替换为绿色

在下面的图像中他们是hud以及如何更改灰色替换为另一个绿色

提前致谢.尼米特帕雷克.

mis*_*may 12

MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
HUD.color = [UIColor purpleColor];
...
Run Code Online (Sandbox Code Playgroud)

  • 不适用于最新的MBProgressHUD代码 (2认同)

ven*_*rti 10

斯威夫特3:

let hud:MBProgressHUD = MBProgressHUD.showAdded(to: self.view, animated: true)

hud.bezelView.color = UIColor.green // Your backgroundcolor

hud.bezelView.style = .solidColor // you should change the bezelview style to solid color.
Run Code Online (Sandbox Code Playgroud)


小智 6

_mHud.bezelView.color = [UIColor blackColor];
_mHud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
_mHud.contentColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)


Nim*_*ekh 5

我找到了这个问题的解决方案并实施到我的项目中。

在以下方法中使用 MBProgressHud.m,它们是管理 Hud 背景颜色的颜色,因此我们更改 CGContextSetRGBFillColor 参数的值更改颜色。

如果应用此值,则我们将获得 hud 的绿色。

- (void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context {
    float radius = 10.0f;

    CGContextBeginPath(context);
    CGContextSetRGBFillColor(context, 17.0/255, 64.0/255, 42.0/255, 0.8);
    CGContextMoveToPoint(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect));
    CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMinY(rect) + radius, radius, 3 * M_PI / 2, 0, 0);
    CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMaxY(rect) - radius, radius, 0, M_PI / 2, 0);
    CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMaxY(rect) - radius, radius, M_PI / 2, M_PI, 0);
    CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect) + radius, radius, M_PI, 3 * M_PI / 2, 0);
    CGContextClosePath(context);
    CGContextFillPath(context);
}
Run Code Online (Sandbox Code Playgroud)


Mar*_*cas 5

MBProgressHUD.m有一个“ drawRect:(CGRect)rect”方法,您可以在CGContext函数中找到设置的灰色:

CGContextSetGrayFillColor (context, 0.0f, self.opacity);
Run Code Online (Sandbox Code Playgroud)

您可以将CGContextSetGrayFillColor替换为另一个使用RGB(或其他)颜色类型的函数:

CGContextSetRGBFillColor (context, 0/255.0f, 132/255.0f, 200/255.0f, 0.9f);
Run Code Online (Sandbox Code Playgroud)

在此处检查完整的CGContext参考: