Set Background Color Globally On On UIButtons - ios

What is the best to change globally all UIButtons background color? I already set the tint globally
[[UIApplication sharedApplication] delegate].window.tintColor =

[[UIButton appearance] setBackgroundImage:[UIImage imageNamed:#"button.png"]
forState:UIControlStateNormal];
Or
[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];
Here's some more info on the appearance proxy: http://developer.apple.com/library/ios/documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html

Check this out:
[[UIButton appearance] setBackgroundColor:[UIColor redColor]];

Related

iOS 11 UINavigationBar Back button image color issue

I am facing issue in iOS 11 with custom BackButton Image color.
BackButton Image works correct in versions lower the iOS 11.
I have customized the Back Button Image of UINavigationBar by using following code.
[[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:false];
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 5.0f, 0);
UIImage *backArrowImage = [[UIImage imageNamed:#"icon_nav_back"] imageWithAlignmentRectInsets:insets];
[[UINavigationBar appearance] setBackIndicatorImage:backArrowImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backArrowImage];
It displays a proper image with default color of image in versions lower than iOS11
But, In Version iOS 11 its color and size have been improper.
Please provide proper solution to resolve this issue.
I have tried Tint Color also, but it doesn't work.
// untested code
// try to see if you can access the back button directly
NSArray *leftBarButtonItems = self.navigationController.navigationBar.items.firstObject.leftBarButtonItems;
for (id barButtonItem in leftBarButtonItems) {
UIBarButtonItem *item = (UIBarButtonItem*)barButtonItem;
if (item) {
item.tintColor = [UIColor whiteColor];
}
}
Follow this link: Swift how to change tintColor of backIndicatorImage
set image on this method setBackIndicatorTransitionMaskImage Might be help!
[UINavigationBar appearance].translucent = NO;
[[UINavigationBar appearance] setBackIndicatorImage:backArrowImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backArrowImage];
Updated use following code it's definitely set back image
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backBtn setBackgroundImage:backArrowImage forState:UIControlStateNormal];
[backBtn addTarget:self action:#selector(goback) forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0, 54, 30);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
self.navigationItem.leftBarButtonItem = backButton;

How to make UINavigationBar fully transparent or gone like this only title and UIBarButtonItem could be seen

As you can see, the UINavigationBar is fully transparent. Only the title and UIBarButtonItem is visible. And the status bar has the same colour as UITableView's background colour. Right now, I have finished to make the table view and cell has the same effect as the pic. But how to make the navigation bar and the status bar has the effect too?
Try this one
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
Try this !
[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
[self.navigationController.view setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor clearColor]];

Change background of a uinavigation right button?

I am successful in changing the text of the right navigation button by given code. But i also want to change it has a delfault background .
I simply want to show a text with transparent background.
I have also tried
UIBarButtonItem *rightBtn=[[UIBarButtonItem alloc] initWithTitle:#"MyTitle" style:UIBarButtonItemStyleDone target:self action:#selector(myMethod)];
rightBtn.tintColor =[UIColor clearColor];
but still showing a button background.
Is there a way to achieve it by changing any different style which don't have background. or is there an other simple way to change button to a text with no transparent background.
You can use this:
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
btn.backgroundColor=[UIColor clearColor];
[btn setTitle:#"Title" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBtn=[[UIBarButtonItem alloc] initWithCustomView:btn];
[self.navigationItem setRightBarButtonItem:rightBtn];
Add this in viewDidLoad:
[self.navigationItem.rightBarButtonItem setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

How to set UISwitch border color?

My app has:
[[UIView appearance] setTintColor:[UIColor whiteColor]];
And here is what I have when on:
and off:
I need to make UISwitch border visible like in Settings.app:
Your [[UIView appearance] setTintColor:[UIColor whiteColor]]; is interfering with the tint color of your switch. The command to set the tint color is self.mySwitch.tintColor = [UIColor grayColor]; which sets the color used to tint the outline of the switch when it is turned off.
Will you please try adding this line to your AppDelegate's didFinishLaunchingWithOptions
[[UISwitch appearance] setTintColor:[UIColor grayColor]];
This should apply the chosen Tint color on all your UISwitch controls.
Rather than using the appearance proxies you can also use:
[self.mySwitch setThumbTintColor:[UIColor blueColor]];
[self.mySwitch setOnTintColor:[UIColor redColor]];
ie. Use setOnTintColor for the background/border color.

Change UINavigationBar Tint Color

Hi I am trying to change the tint color of a newly created navigation bar but i am having difficulty getting the tint color to change and have tried various ways of implementing tintColor. Here is how I am creating it.
UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];
[navBar setTintColor:[UIColor redColor]];
[settingsView addSubview:navBar];
Do I need to approach it differently or redraw it?
Can you try this,
[navBar setBarStyle:UIBarStyleBlackOpaque];
[navBar setTintColor:[UIColor redColor]];
iOS 7 Has a method called setBarTintColor which works perfectly
Worked perfectly for me!
[self.homeNavigationBar setBarTintColor:[UIColor whiteColor]];
Try this:
[[UINavigationBar appearance] setBarTintColor:[UIcolor redcolor]];
use this code
UIColor *appcolor=[UIColor colorWithRed:63.0/255.0 green:148.0/255.0 blue:246.0/255.0 alpha:1.0];
[[UINavigationBar appearance] setBarTintColor:[UIColor appcolor]];

Resources