【问题标题】:ios "Data Loading" Notification with transparent backgroundios“数据加载”通知具有透明背景
【发布时间】:2012-02-29 03:28:01
【问题描述】:

我正在尝试在 iOS 中创建一个视图,让用户知道他们的数据正在加载……它的中间应该有一个 200x200 的圆角框,带有一个微调器和“数据加载中……”字样和透明背景。

除了我的 200x200 圆角框也是透明的之外,这一切都正常。

这是我正在使用的代码:

UIView *loadingDataView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 367)];
loadingDataView.alpha = 0.4;
loadingDataView.backgroundColor = [UIColor clearColor];
UIView *viewWithSpinner = [[UIView alloc] initWithFrame:CGRectMake(110, 106, 100, 100)];
[viewWithSpinner.layer setCornerRadius:15.0f];
viewWithSpinner.backgroundColor = [UIColor blackColor];
UILabel *msg = [[UILabel alloc] initWithFrame:CGRectMake(5, 75, 90, 20)];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(5, 5, 90, 70)];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[spinner startAnimating];
msg.text = @"Data Loading";
msg.font = [UIFont systemFontOfSize:14];
msg.textAlignment = UITextAlignmentCenter;
msg.textColor = [UIColor whiteColor];
msg.backgroundColor = [UIColor clearColor];
viewWithSpinner.opaque = NO;
viewWithSpinner.backgroundColor = [UIColor blackColor];
[viewWithSpinner addSubview:spinner];
[viewWithSpinner addSubview:msg];
[loadingDataView addSubview:viewWithSpinner];
[self.view addSubview:loadingDataView];

谢谢。

【问题讨论】:

    标签: objective-c ios cocoa-touch uiview transparency


    【解决方案1】:

    您的问题没有确切的答案,但请查看开源 MBProgressHUD。它旨在成为私有 UIProgressHUD 类的开源替代品,这正是您想要做的。

    【讨论】:

    • 顺便说一句...我用过这个,我喜欢它!
    【解决方案2】:

    解决方案解决您的问题是,如果您的视图设置为 clearColor,您应该删除 0.4 的 alpha 属性,这就是让您的圆形视图透明的原因(这不是真正的颜色,它只是使视图透明)添加 0.4 的 alpha 是没有意义的。如果您想要的是围绕黑色圆形视图的半透明视图,您应该执行以下操作:

    [loadingDataView setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 andAlpha:0.4]];
    

    这会给你一些白色有点灰色的东西,应该可以。

    不过,我建议你使用我开发的GIDAAlertView Class,你可以在我的 GitHub 上获取源代码和示例应用程序:

    大约需要 3 行代码才能让它工作:

    GIDAAlertView *spinnerAlert=[[GIDAAlertView alloc] initAlertWithSpinnerAndMessage:@"GIDAAlertView Spinner"];
    
    //Show it ...  
    [spinnerAlert presentAlertWithSpinner];
    
    //Later in your code, hide it 
    [spinnerAlert hideAlertWithSpinner];
    

    这是like的样子。

    【讨论】:

      【解决方案3】:

      你说要清楚...

      loadingDataView.backgroundColor = [UIColor clearColor];
      

      你想让它变黑吗?

      【讨论】:

      • 我希望背景(200x200 周围的一切)是半透明的(0.3 的 alpha)...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多