Can't change the tint of segmented control - objective-c

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

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

Changing color of the active whole section in tab bar - iOS 7

(Hopefully) Quick question!
I would like to make a custom tab bar design. Right now it looks like this:
What I've done is:
Changed the background color to dark grey
Changed the tint color to blue.
But I would like to have the background of the active button be another color, like this:
So:
Dark grey background
White icons (Active as well as inactive)
Background of selected button showing the state (blue in this case)
How can I accomplish this?
Thank you.
One way to accomplish this would be following these steps:
Set the background color for the whole tab bar:
tabBar.backgroundColor = [UIColor grayColor];
Have your tab icon images be the color you want them to be (white). Then set up each tab like this:
UIImage *tabImage = [UIImage imageNamed:#"my_image"];
// make sure the original color of the image is used, rather than templating it
tabImage = [tabImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
myViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"title" image:tabImage tag:0];
Set the tintColor of the tab bar to white also so that the selected tab won't change colors:
tabBar.tintColor = [UIColor whiteColor];
Set the selectionIndicatorImage to get a blue background on the selected tab. You'll need to create an image either programmatically or by importing it.

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.

iPhone Buttons Question

Once I tap the button, its default highlight color is blue. How can you change the highlight color of a button. Either in interface builder or by code.
In IB when you select the Button Attributes of your UIButton choose "Highlighted State Configuration" (instead of "Default State Configuration") and select an image for the Background.
Or in code: [myButton setBackgroundImage:[UIImage imageNamed:#"imagename"] forState:UIControlStateHighlighted];
So you rather set an image, than set a color.
You might want to look into code examples of creating your custom UIButton ([UIButton buttonWithType:UIButtonTypeCustom]), using UIImage's stretchableImageWithLeftCapWidth:topCapHeight: instance method.