2011-11-15 65 views
5

Câu hỏi của tôi là "Làm thế nào để thay đổi màu sắc của HUD ở vị trí của màu xám"Làm thế nào để thay đổi màu sắc của hud nơi màu xám

  • Trong hud của họ là một màu xám cho thanh trạng thái.
  • Làm thế nào để thay đổi màu sắc của màu sắc mà thay bằng màu xanh tắt

trong hình ảnh dưới đây của họ là hud và làm thế nào để thay đổi màu xám thay thế với một tắt màu xanh

Cảm ơn trước. Nimit Parekh.

+0

Đây không phải là một built-in kiểm soát UIKit - là bạn bởi bất kỳ cơ hội nói về điều này? https://github.com/jdg/MBProgressHUD – BoltClock

+0

có, tôi đang sử dụng MBProgressHud nhưng trong đó tôi muốn thay đổi màu nền thành hình ảnh mà màu sắc là tắt màu đen tại chỗ tôi chèn ra màu xanh lá cây. –

+0

Chỉ cần chuyển đến tệp triển khai và sửa đổi màu trong phương thức init :) –

Trả lời

4

Tôi đã tìm ra giải pháp cho vấn đề này và được triển khai trong dự án của mình.

Trong phương pháp sau đây được sử dụng vào MBProgressHud.m là quản lý màu của màu nền Hud để thay đổi màu cho chúng ta thay đổi giá trị của thay đổi đối số CGContextSetRGBFillColor.

Nếu áp dụng giá trị này thì chúng tôi nhận được màu xanh lá cây của 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); 
} 
4

MBProgressHUD.m có một "drawRect: (CGRect) rect" phương pháp, nơi bạn sẽ tìm thấy những màu xám đặt trong CGContext chức năng:

CGContextSetGrayFillColor (context, 0.0f, self.opacity); 

Bạn chỉ có thể thay thế CGContextSetGrayFillColor bởi một chức năng sử dụng RGB (hoặc khác) màu loại:

CGContextSetRGBFillColor (context, 0/255.0f, 132/255.0f, 200/255.0f, 0.9f); 

Check complete CGContext reference here:

3

Phiên bản 0.8 của MBProgressHud cho phép bạn đặt màu theo phương thức init của nó: Nó được đặt thành 0 theo mặc định.

trong MBProgressHUD.m:

- (id)initWithFrame:(CGRect)frame { 
. 
. 
. 
self.color = [UIColor greenColor]; 
12
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; 
HUD.color = [UIColor purpleColor]; 
... 
+1

Không hoạt động với mã MBProgressHUD mới nhất – jjxtra

10

Swift 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. 
+0

Tính năng này hoạt động với MBProgress mới nhất trên Swift 3 – Ahmed

1
_mHud.bezelView.color = [UIColor blackColor]; 
_mHud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor; 
_mHud.contentColor = [UIColor whiteColor]; 
Các vấn đề liên quan