3

私は何度も SVProgressHUD とそのクールな作業をしてきました, 今の質問は, ステータスに応じて SVProgressHUD の色を変更する方法はありますか? 言う、

  1. 成功した場合、 BGの色 (濃い灰色がかった色) はGREENでなければなりません
  2. ERRORの場合、BG の色はREDでなければなりません
  3. ちょうどロードのためのいくつかの他の色。

私は先日からこれを試みていますが、すべて失敗しました。

独自のカスタム ビューを作成し、それに応じて実装することで実行できることはわかっていますが、誰かが既にそれを作成していて、それを使用できる場合は素晴らしいことではないでしょうか。

上記の変更が SVProgressHUD で実行できる場合は、それで問題ありませんが、そうでない場合は、誰かが私に同じための代替の ProgressHUD を提供してもらえますか?

編集: 私はすでに使用してみUIAppearanceました。そこにある問題は、成功を緑色に、エラーを赤色に設定したとします。

初めて成功したときはデフォルトの色で、その後はロード全体が緑色になりますしたがって、成功エラーが初めて発生した後でも緑色になります。

これを実行すると、インジケータは赤色になります。

したがって、主なことは、すぐに反映されるのではなく、コードが実行された後に 2 回目に反映されることです。

4

4 に答える 4

5

この方法で SVProgressHUD の BG Color をカスタマイズできます

-(void)showWithStatusSuccess
  {
  [[SVProgressHUD appearance] setHudBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.4]];
  [[SVProgressHUD appearance] setHudForegroundColor:[UIColor yellowColor]];
  [[SVProgressHUD appearance] setHudFont:[UIFont fontWithName:@"MarkerFelt-Wide" size:16]];
  [[SVProgressHUD appearance] setHudStatusShadowColor:[UIColor greenColor]];
  [SVProgressHUD showSuccessWithStatus:@"Great Success!"];
 }


-(void)showWithStatusError {
   [[SVProgressHUD appearance] setHudBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.4]];
//[[SVProgressHUD appearance] setHudForegroundColor:[UIColor yellowColor]];
   [[SVProgressHUD appearance] setHudFont:[UIFont fontWithName:@"MarkerFelt-Wide" size:16]];
 //[[SVProgressHUD appearance] setHudStatusShadowColor:[UIColor greenColor]];
   [SVProgressHUD showErrorWithStatus:@"Failed with Error"];
  }

編集: あなたの場合、showSuccessWithStatus および showErrorWithStatus Methods.so で SVProgressHUD の BGColor を変更する必要があります。SVProgressHUD.m ファイルに移動して、次のようにコードを変更します

#pragma mark - Show then dismiss methods

+ (void)showSuccessWithStatus:(NSString *)string {
[[SVProgressHUD appearance] setHudBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.4]];
//[[SVProgressHUD appearance] setHudForegroundColor:[UIColor yellowColor]];
[[SVProgressHUD appearance] setHudFont:[UIFont fontWithName:@"MarkerFelt-Wide" size:16]];
[self showImage:[[self sharedView] hudSuccessImage] status:string];
}

+ (void)showErrorWithStatus:(NSString *)string {
[[SVProgressHUD appearance] setHudBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.4]];
//[[SVProgressHUD appearance] setHudForegroundColor:[UIColor yellowColor]];
[[SVProgressHUD appearance] setHudFont:[UIFont fontWithName:@"MarkerFelt-Wide" size:16]];
//[[SVProgressHUD appearance] setHudStatusShadowColor:[UIColor greenColor]];
//[SVProgressHUD showWithStatus:@"Error"];

[self showImage:[[self sharedView] hudErrorImage] status:string];
}

それがあなたのために働くことを願っています。

于 2013-06-05T06:58:31.287 に答える
3

defaultStyle を custom に変更した後でのみ、色を変更できます。たとえば、これはリングを緑に変更します。

[SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
[SVProgressHUD setForegroundColor:[UIColor greenColor]];
[SVProgressHUD show];

その他のカスタマイズ方法はgithub にあります。

于 2016-03-27T17:59:41.413 に答える
1

MBProgressHUD https://github.com/jdg/MBProgressHUDも素晴らしいです。

更新: これを試してください:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.color = [UIColor redColor];

MBProgressHUD のカテゴリを作成できるため、使用するたびに上記を再定義し続ける必要はありません。例:

+ (MBProgressHUD *)showFlashHUDMessageTo:(UIView *) view message:(NSString *) message duration:(NSInteger) duration animated:(BOOL) animated
{
    MBProgressHUD *flashMessage = [MBProgressHUD showHUDAddedTo:view animated:animated];
    [flashMessage setAnimationType:MBProgressHUDAnimationFade];
    [flashMessage setMode:MBProgressHUDModeText];
    flashMessage.labelText = message;
    [flashMessage setMinShowTime:duration];
    [MBProgressHUD hideHUDForView:view animated:animated];
    return flashMessage;
}

X の期間、フラッシュ メッセージを表示します。各シナリオの背景色のカスタマイズなどについても同じことができます。ドリフトを理解していただければ幸いです。

于 2013-06-05T07:20:14.953 に答える
0

SVProgressHUDそれはそれ自体で行うことができます

必要なのは、エラーまたは成功のどちらを表示しているかを示すフラグです。あなたがしたいことは 、 SVProgressHUD.mファイル- (UIColor *)hudBackgroundColorでメソッドを見つけることです

そして、そこで色を設定できます

たとえば、次のように言います。

if (obj.isError == 1) { //For Error Status
    return [UIColor colorWithRed:255 green:0 blue:0 alpha:1.0];
}
else if (obj.isError == 0) { //For Success Status
    return [UIColor colorWithRed:0 green:255 blue:0 alpha:1.0];
}
else {//The Default one OR whatever you like to Set for Loading indicator BG
     return [UIColor colorWithWhite:0 alpha:0.8];
}

お役に立てれば

于 2013-06-05T12:49:03.717 に答える