Create a transparent UIView with some information in it - ios

In my app I take a picture then I add on this picture weather forecast and position with some UILabels and some UIImageviews. For now I'm getting picture like this:
But I will create something like the following picture:
Does anyone ions how to do a stuff like the second picture?
In other word I've to create a transparent section in which I will show the weather forecast, the position and the date.
I hope you can help me

You need to create this hierarchy to create view.Set Alpha as you want.

Wherever u set the view, just add this for example:
yourView.backgroundColor = [UIColor darkGrayColor];
yourView.alpha = 0.5;
U can change the background color to whatever u want...
Notice!
The alpha will effect also the subviews of yourView.
So u can play with it, with some views with transparent backgrounds above yourView..
Good Luck!

If you simply want to set a backgroundColor with transparency (not translucency), you assign background color like this:
yourView.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.5f];
If this is inside UIImagePickerController, you might want to check out the cameraOverlayView property of UIImagePickerController`.

You can add the view layer for achieving this kinda effect in your view controller like i would do if i have to

Maybe you should try changing the background colour of the view. For example make it black and add an alpha value.
For Example:
[yourview setBackgroungColor = [UIColor colorWithRed:<#(CGFloat)#> green:<#(CGFloat)#> blue:<#(CGFloat)#> alpha:<#(CGFloat)#>]];

Related

How to set this Detail View Alpha 1.0 , non transparent in ios?

When I click on Share button. Open Share_view. and its alpha 0.5 but I am add another view on Share view.
But I want to this view alpha 1.0 and its not transparent I want to see full white.
See my Image
I had try this, but this is not working at all:
[Detail_view setBackgroundColor:[[UIColor White] colorWithAlphaComponent:1.0]];
As far as I understand, you are adding Detail_view on Share_view, hence Share_view is the parent for your Detail_view.
Solution -
Make Detail_view a subview of self.view, i.e
[self.view addSubview:Detail_view];
If you want Detail_view on Share_view, you can do this:
Don't set the alpha directly on the parent view. Instead use
[Share_view setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5]];
Now any child view can have its own color and will NOT be transparent.

Why is the background of my table view grey when there are no rows?

Why is the background of my table view grey when there are no rows? I can't see where this is set in storyboard
Even setting the background to white explicitly I still get a grey background
Using the defaults for background also results in this grey background:
this might be due to two reason
a) you haven't set data source and delegate and your main view background color is gray
b) cell background color is gray, set that to clear color
Please add this code viewdidload or viewwillappear method
table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
For me it looks like it is a problem of the UITableViewCells, you should set them to
self.backgroundColor = [UIColor whiteColor]; // or clearColor
then also set the UITableView itself inside the controller to backgroundColor white or grey.
Also the snippet of #Rohitsuvagiya can help to let dissappear the separators if there is no additional UITableViewCell.
Please add line your code in viewdidload or viewillappear
table.backgroundColor=[UIColor clearColor];

iOS how to make subview of a transparent view opaque?

I have a view as the subview of another view, then I set the alpha value of the father view something like 0.5, but this also makes the subview transparent even when its alpha value is set to 1. So how can I make the subview non-transparent(opaque) when its father view has an alpha value less than 1?
The closest you're going to get is colorWithAlphaComponent:. Using something like the following, you can set the alpha component of the parent view's background, and it won't affect subviews.
[yourSuperview setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]];
If you set the parent view to 0.5 all the subviews will also go to 0.5 or less. You'll have to come up with a different design approach.
For Swift 4.2
self.yoursuperview.backgroundColor = UIColor.black.withAlphaComponent(0.5)
The following method worked for me.
superView.backgroundColor = .clear
Now that alpha property of superview is not altered, it won't affect the alpha of its subview. Hence, subviews will be opaque(if you have a background color for it).
You should have two designs for the parent view. One would be the "enabled" design, showing it as it is and the other would be the "disabled" design, which would contain transparent background.
You cannot do this with alpha, as subviews inherit the alpha. If
parent.alpha = x
and
view.alpha = y,
then the real alpha of the view will be:
x * y
I think, You have create View by Storyboard. I had already face this problem. Find the below code, this is correct in my case.
[MyParentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.6]];
Hope, This may help you.

PageControl backgroundColor when used in UIPageViewController

I'm trying to implement a simple tutorial using UIPageViewController in iOS7. I implement all methods in UIPageViewControllerDataSource and it gives me a UIPageControl. Everything works except that the pageControl's background is not transparent so it blocks part of the other views behind it.
I try to change the pageControl's appearance with the following code
pageControl.backgroundColor = [UIColor greenColor]; //works, background is green
pageControl.backgroundColor = [UIColor clearColor]; //not working, background is black.
//updates
It turns out that the black color is the background color of the PageControl's layer. And this Page Control layer is not on top of my own ViewControllers that I used for pages. They are in parallel.So no matter how I modify its colors, I cannot get my ViewControllers to take the full screen.
Is there an easy way to move the PageControl on top of my ViewControllers?
It could be the background of the parent view. I had a similar situation where the background color was actually the background of my parent control, not my own. Here is a tool I use that helped me narrow this down : http://www.sparkinspector.com. Here is another tool that does the same thing : http://revealapp.com.
Also one more thing - not sure if this would apply to your case, but it could be the background layer that might need its color set
CALayer *layer = self.layer;
[layer setBackgroundColor:[UIColor clearColor]];
if you set something to be clear color, the background color then depends on whatever is on the background, the view the page control is in (usually a uipagecontrol) has no background, and this is why you're seeing it as black.

iOS Buttons - add border

I am making my app ready for iOS7. I did conversion and was working with a user. The button in the app does not look like button. Looks very flat. Is there someway to put border or make it stand like a button?
Try this for adding border, It will work
#import <QuartzCore/QuartzCore.h>
then in viewDidLoad
_btn.layer.borderWidth=1.0f;
_btn.layer.borderColor=[[UIColor blackColor] CGColor];
_btn.layer.cornerRadius = 10;
also you can fill the color for making appearance somewhat like button, or best way is to use image there
Apart from BorderColor, you can do it by using Runtime attributes too.
try this , this will set border to button
#import <QuartzCore/QuartzCore.h>
btn.layer.borderColor = [UIColor blackColor].CGColor;
btn.layer.borderWidth = 1.0;
btn.layer.cornerRadius = 10;
With Swift and XCode 6 you can do this.
Click the UIButton element in Storyboard, and go to identity inspector. In the user defined runtime attributes, enter:
layer.borderWidth number 1
If you want nice looking corners
layer.cornerRadius number 5
layer.maskToBounds boolean true
Now this will give you a border but to set the colour you need to do it with code. Go to your view controller, and add an IBOutlet from your button. Note that in this case it's an IBOutlet, not an IBAction. Say you do,
#IBOutlet weak var xButton: UIButton!
Call this in the viewDidLoad function like below to set the colour.
xButton.layer.borderColor = UIColor.whiteColor().CGColor
Thanks!
The design principles in iOS7 have changed. However, if you want to go flatter, but still want a custom button that "stands like a button", you can try out this open source component collection:
FlatUIKit on GitHub
There are two way to simplify button in ios 7
1>Set image : Just like Button using setImage Property for button
2>Set bordercolor borderWidth :
button.layer.borderWidth=1.0f;
button.layer.borderColor=[[UIColor blackColor] CGColor];
I suggest you try one of the iOS BootstrapButton libraries (or clones). Just change UIButton in the storyboard to BButton. There is just no preview in the storyboard.
http://github.com/katzlbt/iOSBootstrapButton
http://github.com/katzlbt/iOSBootstrapButtonDemo
http://github.com/mattlawer/BButton
If you use a background image, move button backward.
Editor>Arrange>send backward
In ios7 buttons are supposed to look borderless. Please see apple's View Transition Guidelines for help.
If you REALLY want the buttons to have a border, do: [button setImage:forState:] to set a customized button image with border.

Resources