如何在Swift的主视图中添加子视图

如何在Swift的主视图中添加子视图

本文介绍了如何在Swift的主视图中添加子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建议如何继续。

如何稍微调暗主视图并显示一些忙碌指示,在某些操作的持续时间内,然后删除调光?

How to slightly dim the main view and display some busy indicator, for the duration of of some action, and then remove the dimming?

用Swift语言。

谢谢!

UPD:在Objective-C I使用早期是这样的:

UPD: In Objective-C I use earlier something like this:

UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.5f;
dimView.tag = 1111;
dimView.userInteractionEnabled = NO;
[self.view addSubview:dimView];

我们如何在Swift中执行此代码?

How this code we can do it in Swift?

推荐答案

操作如下,我已经检查,做工精细在斯威夫特 - iOS设备8

Do as follows, I have checked, Working Fine In Swift - iOS 8

我们都必须初始化用框架查看然后我们必须设置 .alpha 属性以使视图变暗。

We have have to initialize the view with the frame and then we have to set the .alpha property for dim the view.

let testFrame : CGRect = CGRectMake(0,200,320,200)
var testView : UIView = UIView(frame: testFrame)
testView.backgroundColor = UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0)
testView.alpha=0.5
self.view.addSubview(testView)

.addSubview 将在主视图中添加视图。

And .addSubview will add the view inside the main view.

快乐编码:)

这篇关于如何在Swift的主视图中添加子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 07:59