Creating a transparent circle in overlay, around a view in superview - ios

I have a UILabel added as a subview in a UIViewController.
I am adding subview (overlay view) view on UIViewController.view.
How to make a transparent circle in overlay view so that the UILabel is visible from transparent circle.
What I am able to do for now:
I am able to create a transparent circle with hardcoded coordinates.What I want is that I just pass UILabel and get a overlay with transparent circle around UILabel.
Any thoughts.
My source code here

Related

Swift UIVibrancyEffect bug while adding as subview

I´am adding a Vibrancy effect view as subview. When I animate its alpha it comes to this bug:
the view is in a xib with clear background and added to the blured effect view content like this:
let slider = Slider(nibName: "Slider", bundle: nil)
self.view.addSubview(slider)
It should just add the vibrancy effect to the blur view. What it does it friarly add the view with a gray background and then its drawing the vibrancy effect correctly. It should not give the user this gray from before it turns to the right effect.

Get uiview section under uiimageview?

I have an UIView as background, and a UIImageView above it.
What I want to do is fill the UIImageView with the UIView section that is in the back (without the white border)
I tried cropping a snapshot of the background but it doesnt look good. there is always a difference.
Make the background UIView a subview of the UIImageView and then set the property of the UIImageView yourImageView.clipsToBounds = YES
Use CALayer mask. The mask will be the smaller image view, and will be assigned to the background view's mask property.

uiscrollview zoom to overlay rect

I want to tap to zoom a UIImageView and put it inside a overlay.
Just like this picture.I want to put the cyan color rect to the blue one.How can I do this?
You can use multiple CALayers. CALayer can be overlaid easily, as you can stack sublayers

how to get the default style of uinavigationbar for a uiview

I am trying to make an uiview look just like the default uinavigationbar in ios 8.
I don't want to hardcode the values so would like to take the uinavigationbar color, height , width and the border at the bottom and apply the same to a custom uiview.
Is there any way I can achieve it ?
self.headerBar.backgroundColor = self.navigationController.navigationBar.backgroundColor;
I tried the above but it didn't work.
K I finally had to combine the following
[UIColor colorWithRed:(247/255.0) green:(247/255.0) blue:(247/255.0) alpha:1];
for the uiview colour than had to put in another uiview that i added as a subview to the original view with small height so that it looks like a border and gave it colour dark gray and alpha 0.4f. One thing to note here is that the border can also be created using layer but that by default doens't take care of orientation changes.
As for height width just gave the height width as per the superviews bounds to which this custom navigation bar is to be attached.
Well you can use UIToolBar and set its properties accordingly as in UINavigationBar, like tintColor, barTintColor, translucent, etc..
Note: UIToolBar inherits from UIView
If you are using UIView and want to get the navigation bar color then its the barTintColor property you should use and not the backgroundColor
self.headerBar.backgroundColor = self.navigationController.navigationBar.barTintColor;

iOS UIView 3D Rotate and SubViews

I am easily rotating my UIView using CATransform3DMakeRotation but the problem is occurring when em adding a SubView after the rotation. It is adding it as rotated..
This is my view before the rotation
This is how i am rotating my UIView
aCustomView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);
and after that em adding a custom Badge on it by this
JSCustomBadge *onlineUsersCountBadge = [JSCustomBadge customBadgeWithString:#"1"];
CGSize size = onlineUsersCountBadge.frame.size;
onlineUsersCountBadge.frame = CGRectMake(imageViewRect.origin.x+20, imageViewRect.size.height*0.3, size.width, size.height);
[aCustomView addSubview:onlineUsersCountBadge];
This is my view after rotation and added Subview
If I understood it well, you want the view to rotate but the badge to stay normal.
In my opinion, the best approach to this problem is to create an invisible subview containing all the elements (UIViews) you want to rotate (such as the background image). You then shouldn't apply the rotation to the full view, but only to that subview. Doing so, if you want to add an element which shouldn't be rotated, such as your badge, you add it to the main non-rotated view and not to the rotated subview.

Resources