Creating a transparent UIview - ios

Unfortunately it is not completely clear what I am trying to do from the title. I want to create an interactive tutor for my IOS application. At the moment I have a simple UIviewcroller with some images, but I want to make it more interactive. I want to add ontop of my normal UIview a second UIview which is partially transparent to enable the user to see what there is below it, and in some parts, invisible. there are the parts that the user has to touch. on this UIview there will be arrows, labels, and other information. Is this possible? If a UIview is covered by another, can I make it possible for the user to interact with parts of the one below it?

Set view.userInteractionEnabled = NO; to disable interaction.
And view.backgroundColor = [UIColor clearColor]; for a transparent background.
Touches will go right through the view to the next one below it.
EDIT:
Alternatively you could try setting view.alpha = 0.0f;. This will make the view transparent. Then you add any buttons and labels to this view. These buttons will be visible and work as expected, but tapping anywhere else will pass through the transparent view. If alpha is below some threshold (not sure about the exact value), touches are ignored and passed to the next view.

On the subview you want transparent set userInteractionEnabled = FALSE. You can also do the same thing with UIWebVIew, UIImageView, etc. also you can set the background color to UIColor clear color. That way it's see through to the layers below.

Try making top view transparent and add a third view below and make its bg-color black and set alpha 0.5

Related

I want transparent UIView but not the elements which I added over it

First of all sorry for the Title. I didn't knew how to exactly convey my problem. So my problem is that I have set black color in the background of a UIView and I've made it transparent. But the UI elements which I am adding over it (e.g Buttons, Labels etc) is also getting faded along with the UIView. For example if I set the alpha of UIView to be 0.5 then it automatically applies to all the controls I've added on that UIView which I don't want. So please tell me how to save elements from getting faded.
If you just have to make view transparent not the subviews, then go with
self.view.backgroundColor=[UIColor clearColor];
What it does is, it will make background view transparent, instead setting alpha property will fade subviews also.
instead of writing in code. we can set it in Interface Builder also. By selecting the background color in the Attributes Inspector in the IB you have to click on background color property and select other and there you can set the alpha or any color you want directly which reduces the code.
#Rahul
You can use something like:
view.backgroundColor=[[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.5];
This will keep the transparency solely to the background but not the subviews.
What you need to do is, don't change the alpha of the UIView, instead, set backgroundColor with the desired transparency, e.g. if you want to have half transparent black, do view.backgroundColor = [UIColor colorWithWhite:0. alpha:.5];
Good Luck!

How to remove rounded corners in PopoverView?

I built a custom Popoverview, but fail to remove the content's rounded corners.
Tried to set .layer.cornerRadius = 0.0 in almost every view in found, with no success.
Image Link: Custom Popover
Red border is of UIViewController used to init the UIPopoverController with, green is background of custom UIPopoverBackgroundView.
Answer from this thread: UIView default styling has rounded corners?
There is no supported way to make the view inside of your UIPopoverController not have rounded corners. The internal code of the UIPopoverController adds your view to a view with rounded corners that clips to bounds.
There may be a hackish way to do it, i.e. waiting until the UIPopoverController is shown and then traversing through all of the parent's of your view and setting them all to have cornerRadius = 0; and clipsToBounds = NO;, but even if you find a solution it might not be compatible with all versions of iOS and if Apple changes some internal code of UIPopoverController in the future then your solution could break.
If you really want to do this then the best way to go is to create your own class that mimics the UIPopoverController functionality.

Overlaying view with remove button

I have searched high and low, and maybe because of not defining the problem correctly, I can't seem to figure out how to achieve the following:
I want to add a overlaying transparent view with a remove button. Any thoughts or tutorials I can use?
I have looked at the following but I want to have it fullscreen with a remove button:
How to Implement a Cool Alert/Information Overlay on iPhone?
Just create a new UIView (let's call it OverlayView) in interface builder, with the size of the main view, and above the others, with clearColor background color. Inside that UIView put an UIImageView with the overlay image (it has to be a semi transparent png) and UIButton for closing (on tap remove the OverlayView from superview)

Problems with UIView clearColor

I am working on building a framework for iOS. The way that works is that say an app uses my framework and calls it to work. The framework presents a view controller on top of the calling app.
Now where I'm stuck is that I have set the view's background color to be clearColor. But whenever the view controller of the framework loads up, the background is set to Black. If i try setting the color to something like Red, Blue, etc. it works perfectly fine. But when I set it to clearColor it shows a Black screen!
I have seen some questions regarding the same matter but all of them suggest setting transparency of the view to NO. I have done that already and it isn't working. So please suggest a solution other than the one that requires you to set the opaque property.
Thanks.
The problem is that if the view with a background of clearColor is the only view, the screen will be black because the view can't be clear if there is nothing under it. To use a view with a clear color, there would have to be a view under it.
You don't want to present the view controller, rather you want to add your view controller's view as a subview to the currently presented view controller.
That is if I am understanding you correctly, it sounds like you want to create an overlay.
Had the same problem while setting clearColor from within initWithFrame: for a custom UIView. Letting the superview set the background color to clearColor worked.
CustomView *uv = [[CustiomView alloc] initWithFrame:rect];
uv.backgroundColor = [UIColor clearColor];
[self.view addSubview:cv];

ios greying the screen

I'd like to create a function that essentially translucently greys out the screen. For example, if you hold the off button on an iPhone/iPad the screen greys out and gives you the option to turn off the device. I'd like to implement the same type of thing. If a function is called, grey out a screen and include a button on the screen, and if the button is pressed it goes back to normal.
My guess is that you would create some sort of new view and place it on top of the current view, but I am not sure how to do that.
Create a UIView subclass that has a background color of [UIColor blackColor] and set the alpha value for that view to 0.5. When you add it as a subview over whatever you view you want to obscure, it should look roughly like the "Power Down" screen tint.
Add a button to that (at full alpha) and it'll look super slick.

Resources