UItextfield not rendering background color - ios

When UITextfield is visible on viewdidload method, It's background color is visible. However, If the text field is kept hidden until some event occurs, It's background color is not visible.
In the image, I have given text field white color background with an alpha value.
In first case color is visible, however in the second case, background color seems to be the clear color.
These text fields are inside UIStackView.

When textfield is in stackView call
self.field1.isHidden = false
self.field1.setNeedsDisplay()

Related

How do I make my UIButton title have some padding?

Let's say I have a UIButton with a size of 120 wide by 30 high. I set an attributed title on it with centered text and I set a background color on the text of the attributed text for the .highlighted state.
When the user highlights the button, I want the background that shows around the title to have the same frame as the button.
I've tried positive and negative values for the button's titleEdgeInsets and contentEdgeInsets with no luck. Any suggestions here? Thanks
The easiest (meaning most controllable) way in my opinion is to use a button subclass and override titleRect. It's called when highlighted and when unhighlighted so you get a chance to change your answer depending on the state.
However, that won't change the size of the background color of attributed text, because it applies only to the text. You'd need to change the background color of the title label itself.

Set the background of UILabel to transparent black

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

How to set the background of a textView to a dark color and continue to see clearly the text selection?

I would like to set the colors for a textView to dark to avoid to stress the eyes when working on text.
If I set for example the field background to be black and the text to be white, the text color selection becomes a bit hard to see.
This is the code I'm using:
mainTextField.backgroundColor = UIColor.black
mainTextField.textColor = UIColor.white
Is there a way to have te selection of the text more visible?
I believe the text selection color is managed by the tintColor. You could set it to whatever you like by setting mainTextField.tintColor = UIColor.orange
UITextView text selection highlight color is determined by either the global or the view tint color.
You can set the color in Storyboard, by going to file inspector and setting the global tint color, or in attributes inspector of UITextView to apply it specifically for that view.
I also suggest that you set text color to Light Text Color.

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)

UIButton doesn't get filled entirely with color when in selected state

calling button.selected = true does not fills the entire button frame with tint color.
Expected result
The button should be filled entirely with the tint color in selected state.
Actual result
The tint color only filled the the area around the text in button.
How to fill the entire button frame(area) with the color when the button is in selected(or any other) state?
Use the backgroundColor instead of tintColor.
You can set it in the Storyboard button's properties. Under "view" section.
As David already said, try changing the background color instead.
If you want to change it through storyboard, then have a look at the attached screenshot.

Resources