Transparent NSButton shown with unwanted backgroundColor - objective-c

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

Related

Can't change the tint of segmented control

I have some problem with segmented control. I can't change the tint color, what ever color I set for the tint, segmented control is always gray as you can see on the picture.
Below is the code I'm using, changing the color of the button works.
UIColor *newTintColor = [UIColor colorWithRed:(30.0f/255.0f) green:(98.0f/255.0f) blue:(134.0f/255.0f) alpha:1.0f];
[btnLogin setBackgroundColor:newTintColor];
[btnLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[rememberMe setTintColor:newTintColor];
I forgot one thing, on application start segmented control has newTintColor, after login in application is displayed new view (split view), when user clicks on settings button, view for settings is displayed. Settings view has one segmented control for which I also can't change tint color (it is always gray) and logout button, if user clicks on logout button login view is displayed again and segmented control has gray tint instead of newTintColor.
The gray color is a clue: it suggests that this view's tint adjustment mode has at some point been set to UIViewTintAdjustmentModeDimmed and then has never been set back to Automatic. See the docs on UIViewTintAdjustmentMode:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/doc/c_ref/UIViewTintAdjustmentMode

How to make a view transparent without transparent subview on that

I have a probem like this. We know we can make transparent an UIView by changing Alpha value of that view. But I dont want to make transparent buttons which are inside that view. My problem is when I set the parent view alpha, button also get transparent and button title not visible clearly. How can I overcome this problem.
Set the background color of the UIView with variable alpha, like this:
view.backgroundColor = [[UIColor white] colorWithAlphaComponent:0.5f];

UISegmentedControl tint color isn't drawn correctly on iOS 7

I want to change the color of a UISegmentedControl on iOS 7. If I change the tint color in the Interface Builder, parts of it are drawn in the tint color, and parts are drawn in the standard blue.
The image ought to make this clearer. I have selected red as the tint color.
I get the same behaviour on both the simulator and on the device.
If I tap items on the segmented control, they're redrawn in the requested tint color.
If I specify the tint colour in viewDidLoad, everything works correctly.
[segmentedControl setTintColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]];
Why doesn't the Interface Builder color work?
(It feels like the color property hasn't applied correctly at the time the control is first drawn, but I have no evidence to back that up.)
I have the same bizarre behavior. The only workaround I could come up with was to switch the tintColor to something else and then switch it back in viewDidLoad
[self.mySegmentedControl setTintColor:[UIColor clearColor]];
[self.mySegmentedControl setTintColor:self.view.tintColor];
If you don't want to write code, there is another workaround that can be done in the storyboard.
Keep the tintColor of the view as the default. The segment control will work then. The downside is that you will have to set the tintColor for each component on your view.

Making rest of view gray when using UISearchBar

I want to mimic what seem to be the standard UI for using the UISearchBar, and right now I trying to make the rest of the view gray, when I begin searching, and I tried doing that by just setting the background color of the view to gray, but I am using sections in my UITableView, and they are not turning gray. Anybody have any reasons why that is?
The reason you're not seeing the section headers fade to gray is because they are drawn on top of the gray background, and are opaque; in other words, their alpha is 1.
If you're looking for a suggestion to get the effect you want, my first reflex would be to add an overlay UIView as a subview of the area you want to be "grayed out", and change its background color when certain events occur. Something like this:
// You have to choose what view is the one that needs to be grayed out.
// I'll call the view you want to gray out "viewToBeGrayed"
UIView *grayOverlay = [[UIView alloc] initWithFrame:viewToBeGrayed.frame];
// Initially, the overlay should be clear
[grayOverlay setBackgroundColor:[UIColor clearColor]];
[viewToBeGrayed addSubview:grayOverlay];
Then, when you want to "gray out" viewToBeGrayed, just change the background color of grayOverlay to some translucent gray value:
[grayOverlay setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
Finally, when you want to get rid of the "grayed out" effect, just set the view back to clear:
[grayOverlay setBackgroundColor:[UIColor clearColor]];
That should be a good place to start. Comment if you need any additional help.
Use the standard UISearchController for your tableview search needs.

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