Set the background of UILabel to transparent black - ios

I have a UILabel that whose background I want to set to black with alpha component so that this label can have a transparent black background.
In the storyboard when I set the background to the colour I want with an alpha component even the text of the label that is in white colour becomes lighter with the alpha component.
To overcome this problem I embedded the label in a UIView and even then the same problem persists.
How can I overcome this problem. Any help will be appreciated.

You can Do only With label make IBObject an write following line.
label.backgroundColor = UIColor.black.withAlphaComponent(0.4)

Instead of changing the alpha value, change the opacity of the label background color in storyboard.
For better understanding, I have taken an imageView and placed a label at the bottom of imageView and changed the background color of the label and textColor to white. At this stage you can't see the image behind the label.
Now, go to attributes inspector and select the label background color. There you can see the opacity and change it's value. Here I have made it 50%, you can change it to whatever you want between 0 to 100 until you get your desired transparency.

create the UIview with black background color and add the UIlabel inside the view and set the alpha to 0.5 of view . finally you get the black transparent, for e.g
if you need the label text in bold change the view hierarchy
place the UILabel fist then add the UIView.

Place the UILabelabove the UIView, not inside it.

Assume that we are talking about v1 the view that contains your label , if v1 is over another view that has bright colors then when your v1's alpha get lower your label white text color will become harder to see , the text color has nothing to do with the background alpha component , so you need to reconsider using the white color or the alpha component background or the view that is behind v1 make it darker that's all we can say

Related

UI Text Field Design

So, I was trying to mimic a video that uses sketch to design a login screen I really like. I had a question about how I can make a text field in Xcode look like the one that is being designed in the video.
Here is the video link: https://www.youtube.com/watch?v=gA_hFHkhqFM&t=87s
Here is a picture of the text field I want to design:
Any help is appreciated!
This is how to do it in the storyboard
Find/Create a blurry image and set it as an image view's image. Fill the view with the image view and add constraints. Add a new text field on top of the image view. Set these things:
border style to none
Text color to white
Background color to a black color with an alpha value and tint color to white as well.
This can be set by using the RGB slider in the color picker. Use the slider at the very bottom to adjust the alpha:
The easiest way to do it is to add a UIView with a black background. Set its alpha to 0.7.
Then add a UITextField on top. Set its border style to none, then the background color to clear.
You're done!

Original UILabel for transparent view with opacity alpha 0.5

I have a CollectionView cell with labels, I want to make that view transparent with alpha 0.5 but not the UILabel's. I have a content view with clear background, and for the view above the content view, given with the background white with alpha value 0.5. The CollectionView is transparent but my problem is that the labels are also slightly transparent it's not much clear. please help me if anyone knows the solution.
You can achive this effect by putting your label into a view and then changing alpha component of view itself like this:
alphaView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
Label shouldn't be transparent then. Ofc you need to set your label background color to clear.
You should not set the alpha value of the view. If you set the alpha value of a view this value takes effect on all subviews, too. You should set the alpha value of the background color of the view.
You should not set alpha value.
Instead you can set the background colour of the uicollectionviewcell to be clear colour. In this way your collection view cell will be transparent.
Then you could give whatever color to the labels.

UILabel text color is light

In UIView i have added a label , who's text color is white but when I changes the Alpha of the UIView to 0.25 the color of UILabel lighten If I change Alpha back to 1.0 the UILabel text color result is what I expect.
I have no clue how to change setup.
Screenshot is included.
Also the Alpha is same for the Toolbar and the result is same , icon image of button is also light.
It is normal behaviour because if you change alpha of the parent view it will be propagated to the child views. You can maybe change not the parent view alpha but use colorWithAlphaComponent for this view background color.
e.g.
yourParentView.backgroundColor = UIColor.blueColor().colorWithAlphaComponent(0.5)

Setting UIViews layer.cornerRadius adds gray lines around the view

Both background and border color are set to white, there is no gray color in my code anywhere.
But when I set views cornerRadius I see two gray lines left and right from the view(sometimes up and down too, depending on the UIViews function)
Although when I set views backgroundColor to clear, lines disappear. Any reason for this to happen?
EDIT:
This only happens on iphone device, not on simulator, dont know why :/
Here I have one big white UView and 8 smaler ones inside it, and I am using constrains for the autolayout(but no problem there), and when I set all of these small views background color to clear, they disapear(also this big white view is responsible for the few of these gray lines)
And solution to the problem is either removing cornerRadius or seting background color to clear.

UITabBar remove the black background

As the title states, I haven't been successful in removing the black background in the UITabBar.
I know it is possible to add a subview on top of it. But I want it to be transparent so if I add a transparent subview on top of it, it will just have the underlying black color.
Setting the tintColor made me able to change the color of the UITabBar, but when I change it to clearColor it will just be black again.
Anybody know how to remove the underlying image or color so it will be transparent?
When they added the tintColor property in iOS 5, they also added a number of other appearance-customization functionality to UITabBar. See, backgroundImage and selectionIndicatorImage, and the finishedSelectedImage and finishedUnselectedImage properties of UITabBarItem.

Resources