How to create online status view | Swift 5
To build the online status view circle in swift programatically, we’ll go through following steps:
1: Create an ImageView that will contain the main image.
2: Create a dummyView exactly above the imageView which will take small circle as a subview.
3: Finally create small circle view and align it in such a way that it gets in the exact position as above.
Step 1 :
First create a UIImageView, which will hold the profile picture.
Then ,also give it some constraints.
Step 2 :
Repeat the same procedure, and create a UIView with exact constraints. But while creating the view, keep clipsToBounds = false.
Step 3 :
Finally, we will create small circle view, and we will add it as a subview of the dummy circular view.
Give it constraints for height and width.You can give those accordingly.
Now, the moment of truth, that is to give constraints for x and y position. For doing that, we’ll write a function, that will return us the exact position for x and y coordinates of our view according the angle we provide.
In the above function, we are giving angle as a parameter, and based on that angle, we are calculating the position, so that the view will remain intact at the desired position. Now we will give the remaining two constraints.
Run the project, and you’ll be fascinated by the result!