2012-02-29 101 views
1

我想在iOS中创建一个视图,让用户知道他们的数据正在加载......它应该有一个200x200的圆角框,中间有一个微调框,单词“数据加载...”和透明背景。ios“数据加载”透明背景的通知

这一切工作除了我的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]; 

感谢。

回答

3

您问题的解决方案是,你应该去掉0.4的alpha属性,这是什么把你的全方位视角透明的,如果您的视图设置为clearColor(这是不是一个真正的颜色,它只是使视图透明),添加0.4的alpha是没有意义的。如果你想要的是你周围的黑色圆图半透明视图,你应该做到以下几点:

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

这将会给你一些whiteish有点灰,应该工作。

然而,我会建议你使用GIDAAlertView一级开发,你可以得到源和我的GitHub的一个示例应用程序:

大约需要3行得到它的工作:

GIDAAlertView *spinnerAlert=[[GIDAAlertView alloc] initAlertWithSpinnerAndMessage:@"GIDAAlertView Spinner"]; 

//Show it ... 
[spinnerAlert presentAlertWithSpinner]; 

//Later in your code, hide it 
[spinnerAlert hideAlertWithSpinner]; 

这就是它的样子like

+0

感谢clearColor /阿尔法解释 – 2012-10-19 10:57:29

6

没有完全解答您的问题,但请查看开源MBProgressHUD。它旨在成为私人UIProgressHUD类的开源替代品,而且正是你想要做的。

+0

顺便说一句...我用这一个我喜欢它! – 2014-06-02 13:41:48

0

你告诉它要清楚......

loadingDataView.backgroundColor = [UIColor clearColor]; 

那你希望它是黑色的?

+0

我想要的背景(200×200周围的一切)是半透明的(.3阿尔法)... – 2012-02-29 03:57:58