Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add subview inside main view in Swift [closed]

I need advice how to proceed.

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

In Swift language.

Thanks!

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];

How this code we can do it in Swift?

like image 984
Alexey Nakhimov Avatar asked Jul 21 '14 07:07

Alexey Nakhimov


People also ask

What is addSubview in Swift?

Adds a view to the end of the receiver's list of subviews.

How to add subview in iOS Swift?

How To Add, Insert, Move, Remove Sub View In iOS Swift 1 Manage Swift View And Subview Example Demo. First let us look at this example in a video as below. ... 2 Manage Swift Subview Functions Introduction. parentViewObject.addSubview ( subView : UIView ) : Add a subview to parent view. ... 3 Manage Swift Subview Example Source Code.

What are navigation links in Swift UI?

One of the cool things that are wrapped into navigation links is that Swift UI automatically adds a back button on the secondary view and will know to navigate back to the previous view when selected. Navigation links make connecting views a breeze with Swift UI!

How to add detail view for each row in list using navigationlink?

Today, we’re going to add a NavigationView to our List and implement a detail view for each row in the List using NavigationLink. First, we need to embed our List in NavigationView and set its title using navigationBarTitle modifier. Entire code for the List should look like this:

How do I push a detail view from a list?

The List has a large title and with each row having a navigation arrow indicating that the user can tap on it to push a detail view.


1 Answers

Do as follows, I have checked, working fine in Swift

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(x: 0, y: 100, width: 100, height: 100)
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)

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

Happy Coding :)

like image 54
Ashish Kakkad Avatar answered Sep 21 '22 11:09

Ashish Kakkad