Problems with UIView clearColor - ios

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

Related

ios How to change content view color except navigation bar color

In my application i would like to change color of content view not the navigation bar color
I have written like self.window.backgroundColor = [UIColor redColor]; but its changing whole content color including navigation bar color.
You could just make your UINavigationBar to not be translucent. If you are working with Interface Builder then you should go to your UINavigationController, select the UINavigationBar and uncheck the Translucent property. If you are doing this in code you can just call self.navigationBar.isTranslucent = false.
You need to set self.view.backgroundColor on any view controllers you want to adopt your new colour. Setting it on the window causes the navigation bar to change colour because it has transparency and therefore you can see the window background colour through it.
I recommend subclassing UIViewController and setting this in viewDidLayoutSubviews. Then, making all your other view controllers subclass this one. This means you don't have to write the same code for every view controller.

How to change UIPopoverPresentationController's arrow color without drawing my own

I want to change the color of the arrow that UIPopoverPresentationController uses to point at its source. The only way I can see to do this is to subclass UIPopoverBackgroundView and write drawRect and draw the popover border and arrow myself. That's a pain, because there are little niceties in the default popover like rounded corners on everything. And I want to make it feel as much at home on the platform as I can.
Do I really have to draw my own popover arrow just to change the color of the arrow?
Update: I've tried setting the backgroundColor of the UIPopoverPresentationController, but it appears to change the color of everywhere the arrow might draw. I've seen it work before, but I can't nail down what makes it work when it does. See screenshot of setting the color to red. The blue is the content of the navigation controller in the popover. It's supposed to be pointing at the button.
The UIPopoverPresentationController's backgroundColor property should handle that for you
Update
I've used this approach a number of times and have never seen what you have in your screenshot. Are you sure you are using popoverPresentationController.backgroundColor and not setting a different background color on a view or container? Below is screenshot of non-centered popover arrow. The view controller background is green, the popoverPresentationController.backgroundColor is red. Shown next to the code setting the value.
Update #2
I looked at the project you posted and found the problem (although I'm not entirely sure why it's the problem). You are setting the popover presentation controller's backgroundColor property inside your presented view controller under viewWillAppear:. I suspect that setting the background color like this after the presentation happened is what triggers the bug pre-iOS 10.
If you set the popover presentation controller's backgroundColor inside your presenting view controller's onPopover: method, where you are also setting the sourceView and sourceRect properties (and before you actually call presentViewController:), everything works correctly.

iOS Modal ViewController with Transparent BG and Opaque Foreground

I am trying to create a Modal View in XCode Storyboard with background semi-transparent. On this view I have placed a TableView which I want to appear with opaque background. But unfortunately, both are appearing either semi-transparent or opaque.
Is there any workaround to this?
P.S. I am using Swift as a programming language.
Don't make the tableview a child view of your transparent view,your view hierarchy should be like
View
TransparentView
TableView

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!

Creating a transparent UIview

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

Resources