Customized UIColor doesn't render correctly for UIView background or border. Why? - uibutton

Why can't I use a customized color to paint a UIView/UIButton (background or border), yet I can with a stock color?
Here's my customized color:
Yet, here's the result of the backgroundColor set:
If I were to change to color to a STOCK color:
...then I get the expected result:
Why is this happening; and is there a remedy?
...or could this be a bug?

Try this for initialising the value for myColor
UIColor *myColor = [UIColor colorWithRed:18.0/255.0 green:165.0/255.0 blue:217.0/255.0 alpha:1.0];

Related

Transparent NSButton shown with unwanted backgroundColor

So I have an NSView in which I created some borderless buttons programmatically.
Although I set their backgroundColor property to desired color, they show up like they have a darker shade.
I guess that is the background of Label, not of Button, which does not appear when users choose to reduce transparency in System Preferences.
In that case, I have solved by this line of code:
myButton.appearance = NSAppearance(named: .aqua)
here How I would do it as I mentioned in comment.
The custom view is connected as iboutlet and given green color.
Label has by default no back ground color.
The button has no border and of type Round Rect as you see in screen shot.
The blue color around button is the selection/ active control, but you can get rid of that too.
self.testBtn.focusRingType = NSFocusRingTypeNone;
edit add new image showing scroll bar:
//set background color
button.backgroundColor=[UIColor clearColor]
//then set tint color of button
[btn setTintColor:[UIColor clearColor]];

Layer borderColor and borderWidth is not working for UIButton

I have a requirement to add border color and width to UIButton. I have tried adding layer borderColor and borderWidth to button in code and in storyboard as well.
But its not working in anyway. I have added QuartzCore framework in build settings as well.
This is my code to set bordercolor and width:
self.accountButton.layer.borderColor = [UIColor blueColor].CGColor;
self.accountButton.layer.borderWidth = 6.0f;
Can someone please help me where i am doing wrong?
Try it this way, you can customize the width and height to the way you want it latter:
[self.<your_Button>.layer setCornerRadius:self.<your_Button>.frame.size.height/2];
[self.<your_Button>.layer setCornerRadius:self.<your_Button>.frame.size.width/2]; //
[self.<your_Button>.layer setBorderColor:[[UIColor darkGrayColor] CGColor]];
[self.<your_Button>.layer setBorderWidth:1.0f];
I found the answers. I created a category on CALayer class with method
- (void)setBorderColorFromUIColor:(UIColor *)color
{
self.borderColor = color.CGColor;
}
and then in storyboard, put the run time attribute
layer.borderColorFromUIColor
that's all and happy Me :)

Changing the color of an SKSpriteNode image?

I was wondering if there was a way to change the color of an SKSpriteNode programmatically?? Say I have a texture for an SKSpriteNode that is a box that has a black outline and a white fill color. How would I be able to change the white fill color to a different color programmatically?? (I was thinking maybe a custom method that searched a texture for white pixels and then replace the pixels with a different color) I don't even know if this is possible.
You can set a color to SKSpriteNode and then use colorBlendFactor, here is an example:
image.color = [UIColor greenColor];
image.colorBlendFactor = 0.5;

iOS which is the default UIColor for tabbar icon?

I am changing properly tabbar icon color but I need sometimes to go back to default blue one. Which is the default blue color from palette? UIColor "cyan" and also "blue" are not! Thanks
colorIcon = [UIColor greenColor];
Before you change the color of your tabbar icon, you could save the current color and use that variable to restore the original color.
UIColor *originalColor = tabBar.selectedTintColor;
[tabBar setSelectedTintColor:[UIColor greenColor]];
Restore your original color:
[tabBar setSelectedTintColor:originalColor];
Look carefully and you will see that the color actually is a color-fade using some blue and some light blue or even white.
See this:

100% opacity UILabel over a 50% opacity background (UIView?)

So right now I have a UIView with a UILabel in it. I want the background to have an opacity < 1.0 and the label to have an opacity of 1.0. However since alphas propagate down the view hierarchy, the label ends up with an opacity < 1.0 as well.
Is there anyway to do what I want without making the UILabel a subview of another view??
Just set the background color to be semitransparent:
view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
Or, in Swift:
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
Or, Swift 3:
view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
Note that, in this particular case, UIColor(white: 0, alpha: 0.5) is more concise, but colorWithAlphaComponent will work in general.
Besides being available in code, you can do this quite easily from iB as well:
Within the storyboard, select the view you wish to edit;
From the right panel, make sure the Attributes inspector is opened;
Click on the right side of the "Background" drop down box and choose "Other ..."; it will open a colour picker dialog;
Change the "Opacity" at the bottom to set the background colour opacity.
You can set the background color of the UIView with a semi-transparent color or make the image itself semi-transparent. This way it's a property of the view that is transparent, not the view itself.
You can use this:
self.view.layer.opacity=0.5