UISegmentedControl tint color isn't drawn correctly on iOS 7 - ios7

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.

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

How can I overlay a background color over an NSVisualEffectView and use vibrant controls?

I want to use NSVisualEffectView with dark vibrancy, but I find the effect too pale in some situations, so I'd like to darken the background.
Here is an example app, using NSBox views to provide a darker background.
We can see that the NSBox 'primary' appearance manages to overlay the background and the button happily sits on top of that. However, on the NSBox with custom appearance, the button appears to 'cut' through the background to the visual effect view beneath.
I've tried subclassing NSVisualEffectView and overriding -drawRect: to fill it with a different color and the result is the same.
Is there a way to overlay vibrant controls over other views?
The Visual Effect View seems to have two important layers: Backdrop and Tint. Setting both of these to the "right" black seems to do the trick, but you'll need to do this anytime the bounds change.
for (CALayer *sublayer in self.vibrancyView.layer.sublayers) {
if ([sublayer.name isEqualToString:#"Backdrop"]) {
NSLog(#"Backdrop: %#", sublayer.backgroundColor);
sublayer.backgroundColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.45].CGColor;
} else if ([sublayer.name isEqualToString:#"Tint"]) {
NSLog(#"Tint: %#", sublayer.backgroundColor);
sublayer.backgroundColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;
}
}

Set default tint color for all UIButtons in an app

My iPad app I has a number of UIButtons that when pressed turn blue by default. I could go through each one and set the tintcolor using:
[buttonName setTintColor:[UIColor colorWithRed:151/255.0f green:202/255.0f blue:86/255.0f alpha:1.0]];
But is there anyway of changing this colour by default and for all buttons?
Is there anyway of changing this colour?
If you are using storyboards and Xcode 5.0 or later, the easiest way to do this is to open up your storyboard in Xcode and set the Global Tint color setting in the File Inspector in the Utility area. See illustration below.
Use the UIAppearance Protocol:
[[UIButton appearance] setTintColor:[UIColor colorWithRed:151/255.0f green:202/255.0f blue:86/255.0f alpha:1.0]];
You could subclass uibutton and set the color to whatever you want there. Then any button with that class will have the same color

UITabbar with partially transparent background

Long time reader, first time poster. Please be gentle :P
I'm working on an app and have a background image for a UITabbar element that is transparent for a few pixels at the top. I have searched far and wide, tried many solutions suggested that I could find (setting tint, background color to clearColor, setting alpha to 0.2, etc) but I continue to see a black line where the tabbar should be transparent. I am setting the background as follows (see the lines commented out for some more things I have tried which did not work)
//[[UITabBar appearance] setBackgroundColor:[UIColor clearColor]];
//[self.view setBackgroundColor:[UIColor clearColor]];
//[super.view setBackgroundColor:[UIColor clearColor]];
//UITabBar.super.setBackgroundColor:[UIColor clearColor]];
[[UITabBar appearance] setBackgroundColor:[[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.2]];
//[[UITabBar appearance] setTintColor:[UIColor blackColor]];
[[UITabBar appearance] setTintColor:[[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.1]];
//[[UITabBar appearance] setAlpha:0.0];// setTintColor:[UIColor magentaColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tabbar.png"]];
Screenshot can be fount at http://i.imgur.com/m1tW5.png
The app uses a tabbarcontroller.
When I set the background color to white or any other color, the black line changes color successfully but as soon as I set the color to clearColor the black line comes back.
When I hide the entire tab bar there is nothing crazy behind it and I can successfully see the cream background as I should.
The image is a png with a transparent top where the black line appears as mentioned earlier.
Does anyone have any suggestions on what I could be doing wrong?
Help will be truly appreciated.
Edit: I am using iOS 5.0 and don't care about supporting previous iOS versions (in case that opens up any additional potential choices).
I'm currently trying to solve a similar problem.
I believe the black color is either:
The TabBars Superviews background in which case you can try to set the tabBars superviews background color. I don't have my mac here so I can't try it and I don't see that in your "tried" code.
Or it's the border of the tabBar, in which you can change the bordercolor of the tabBar's frame.
tabbar.frame.borderColor = [UIColor whiteColor];
You will need to import the QuartzCore framework to manipulate the boderColor.
Let me know if it helps.
I decided to go with a "hack-ish" solution I came across elsewhere.
I'm using the same color as the background in areas of the tab bar's background image to create the illusion of transparency. Not really transparent but that's the best I could come up with after countless hours spent on this.
Maybe that'll be a solution that works for someone else in a similar position in the future as well.

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.