UiBarButtonItem Same Color as "Done" Button - objective-c

I want to be able to programatically add a UIBarButtonItem to a Navigation Bar and set it's tint color to the exact same blue shade as Apple's "Done" UIBarButtonItem.
I am already doing this for Apple's red shade in this block of code:
UIBarButtonItem *myDeleteButton = [[UIBarButtonItem alloc] initWithTitle:#"Clear" style:UIBarButtonItemStyleBordered target:self action:#selector(myDeleteItemsMethod:)];
myDeleteButton.tintcolor = [[UIColor alloc] initwithRed:1 green:0.0470275 blue:0.0116515 alpha:1];
self.navigationItem.rightBarButtonItem = myDeleteButton;
I guess all I need are the RGB values.
I'm having a hard time trying to "reverse engineer" a UIBarButtonItem's tint that was made in Storyboard (Can't cast UIColor as text).
And I also realize that Xcode's color palette has an area for "developer" color schemes but it does not appear to include the color for the "Done" button.

I spent about 15 mins with my DigitalColor Meter and basically guessed and checked until I finally got it. The problem is that you're adding a "tint" to a black button to make it blue, so it won't be the right blue. Here's the correct measurements:
[buttonName setTintColor:[UIColor colorWithRed:34.0/255.0 green:97.0/255.0 blue:221.0/255.0 alpha:1]];
Hope it helps someone :)

You want UIBarButtonItemStyleDone rather than UIBarButtonItemStyleBordered.

The proposed color of user1641653 is just the bottom color of the real DoneButton taken with the color meter. The problem is that the shadow of a plain/borderer button is different than the one of a SystemButton. The shadow will change the proposed color by -11, -36, -11.
So if you really want it to look like the real DoneButton you have to add those values to the proposed 34/97/221.
This means:
[yourButton setTintColor:[UIColor colorWithRed:45.0/255.0 green:133.0/255.0 blue:232.0/255.0 alpha:1]];

Related

Setting UITableViewCellStyle2 Tint Color

I can't believe I don't see this anywhere on Google, but I have an odd issue.
I am changing the Global Tint in iOS 7 in the App Delegate:
[[UIView appearance] setTintColor:[UIColor redColor]];
However, when I display a table view with UITableViewCellStyle2 cells, the text title color is still the default blue color.
Any ideas on how I could fix this? I'd rather not subclass it.
Thanks!
simply change the text color.
cell.textLabel.textColor = [UIColor redColor];

UIRefreshControl change color of UIActivityIndicatorView

There is any way to change the color of the "UIActivityIndicatorView" of the UIRefreshControl??
I didn't find anything!
Thanks!!
You can do it by setting the Tint Color of the UIRefreshControl, something like this:
Objective C
[refreshControl setTintColor:[UIColor blackColor]];
Swift
refreshControl.tintColor = .black
This will also change the arrow that expands when you slide.
As the previous answer is outdated, I thought that I would just modify it to Swift 4 and share the solution (credit goes to #subharb).
refreshControl.tintColor = UIColor.white
This line of code will change the color of the UIActivityIndicatorView to whatever color you want it to be :)

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.

Objective C: How to change text color in navigation bar

I have changed my navigation bar color via the following code
navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:#"faf6f5"];
The code worked but the text color also needs to be changed (see screenshot below). Also the refresh button logo on the right is affected as well
The same issue occurs if I navigate to another page in the stack
Question: How can I change the color of the
title text
Back button text and
right bar button icon color?
After I changed the background color of the navbar?
In iOS 7, just use:
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor whiteColor]};
Change [UIColor whiteColor] with whatever text color you want
For the title here's the way:
iPhone Navigation Bar Title text color
And for the custom buttons here's the way:
adding buttons to ui navigation controller bottom bar
To change text color:
_navController.navigationBar.titleTextAttributes
= #{UITextAttributeTextColor : [UIColor blackColor]};
Adding refresh button and color it:
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:#selector(reload)];
[button setTintColor:[UIColor blackColor]];
self.navigationItem.rightBarButtonItem = button;
Variables that effect navigation bar background:
_navController.navigationBar.backgroundColor = [UIColor whiteColor];
_navController.navigationBar.tintColor = [UIColor whiteColor];
_navController.navigationBar.translucent = NO;
I just put together a simple UIViewController subclass that adds a customizable back button that allows you to change text colors. It basically adds some willAppear/willDisappear logic to animate the back button the way the UINavigationController does while using the leftBarButtonItem property. You might extend this to also do the rightBarButtomItem as well.
https://github.com/typeoneerror/BBCustomBackButtonViewController