Modify tintColor in UINavigationBar within MFMailComposeViewController - ios

I'm trying to modify the tintColor in the UINavigationBar for the MFMailComposeViewController, but this doesn't seem to be working.
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [MFMailComposeViewController class], nil] setTintColor:[UIColor blackColor]];
Before anyone quotes Apple saying that "The mail composition interface itself is not customizable and must not be modified by your application", I've previously submitted an app that is live in the App Store where the UINavigationBar had been modified in a similar manner, with no issues during the review process.
It works when I set the appearance for these classes across the entire app like this:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor blackColor];
The issue is that I don't want these appearance settings to apply to all UINavigationBar/UIBarButtonItem instances.
Is my understanding of how to use appearanceWhenContainedIn: incorrect? Or is it something else?
Thanks for the help as always :)

This appears to be a bug in iOS 6.x, my Open Radar - http://openradar.me/radar?id=2984402
Apple has responded to me and it's a duplicate of a previously known bug (#12328070), so it should be fixed soon.
This code will work as expected in iOS 5.
In order to work around this, I suggest you manually apply what you want when you create the MFMailComposeViewController:
MFMailComposeViewController *mailComposerController = [[MFMailComposeViewController alloc] init];
[mailComposerController.navigationBar setTintColor:[UIColor redColor]];
I'll update my answer if I find anything else on the subject.

Related

UILabel appearance doesn't seem to do anything

It seems that [UILabel appearance] doesn't work anymore with latest iOS SDK.
Let's take this as an example:
- (void)viewDidLoad {
[super viewDidLoad];
[[UILabel appearance] setBackgroundColor:[UIColor redColor]];
[self.view addSubview:[[UILabel alloc] initWithFrame:CGRectMake(40, 80, 200, 100)]];
}
This code won't display the label with the red background.
If, on the other hand use this code:
- (void)viewDidLoad {
[super viewDidLoad];
[[UIImageView appearance] setBackgroundColor:[UIColor redColor]];
[self.view addSubview:[[UIImageView alloc] initWithFrame:CGRectMake(40, 80, 200, 100)]];
}
then the red area is visible.
Even if I change the property, i.e. change the font instead, or the text color (and display some text of course), no changes are visible.
On most S.O. questions regarding UILabel and appearance, although some people did have some problems, in general it seems to work, so I don't understand what I am doing wrong here.
The comments from #matt made me find the error. (Unfortunately he has retracted his answer so I can't give him the credits he deserves, if #matt you are listening, please give another answer in order to get the credits).
The reason why it was that, it is because it seems to be a Bug in iOS 12.
Under (beta) iOS 13 the behavior is as expected.

Question mark when tapping or holding font icons

So I recently started some tinkering with my app to get it iOS 11 compatible. Thankfully most of it seems to be.
However I did notice, that in my toolbar if I tap or tap and hold an icon, which is supplied by a ttf file from fontello, I get a question mark box.
Example of icon:
menu = [[UIBarButtonItem alloc] initWithTitle:#"\ue811" style:UIBarButtonItemStylePlain target:self action:#selector(openMenu:)];
[menu setTitleTextAttributes:#{NSFontAttributeName:
[UIFont fontWithName:#"fontello"
size:23],
NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:1.f alpha:1.f]}
forState:UIControlStateNormal];
It works fine in the 10.3.1 simulator. Just iOS 11 seems to be goofed up. I've read about the fixes for devices, which means to update the OS, but the simulator is running 11.2, so in theory it should be fixed.
Is anybody else having this issue? Know of a fix?
Just add title text attributes for UIControlStateSelected also:
[menu setTitleTextAttributes:#{NSFontAttributeName:
[UIFont fontWithName:#"fontello"
size:23],
NSForegroundColorAttributeName:[UIColor greenColor]}
forState:UIControlStateSelected];
As mentioned in the comment, iOS 11 requires you to have a setting for normal state and selected/highlighted state. Below is what is working for me. Not ideal to have extra code depending on many buttons you have, but oh well.
[menu setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"fontello"size:23],
NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:0.f alpha:1.f]}
forState:UIControlStateNormal];
[menu setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"fontello"size:23],
NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:0.f alpha:0.5f]}
forState:UIControlStateHighlighted];

UISlider track image disappears when returning from a specific view

Image 1
Image 2
Image 3
1st image is the settings screen and everything behaves normally
upon the first loading of this screen.
2nd image is the policy
screen which is pushed from the settings screen.
3rd image upon returning from the policy screen back to the settings screen shows the UI Slider now doesn't show the track image. The behavior still works normally, but the track is just gone. It's a very mysterious bug to me. If I go to another screen in the app and then hit settings it works fine again, but when I come from the policy screen the track image is gone.
I am using the default UISlider. I am using xib files for the different screens.
When the Policy Button is clicked...
EditorialPolicyViewController *policyView;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
policyView = [[EditorialPolicyViewController alloc]initWithNibName:#"EditorialPolicyViewController_iPad" bundle:nil];
}
else
{
policyView = [[EditorialPolicyViewController alloc]initWithNibName:#"EditorialPolicyViewController_iPhone" bundle:nil];
}
[self.navigationController pushViewController:policyView animated:YES];
ViewDidLoad - setting up the uislider
NSString *textSize = [[NSUserDefaults standardUserDefaults] valueForKey:#"Text Size"];
float textSizeFloat = [textSize floatValue];
self.textSizeSlider.value = textSizeFloat;
[self.textSizeSlider setMaximumValue:16.0];
[self.textSizeSlider setMinimumValue:11.0];
Let me know if you have any other questions. I am out of ideas on how to solve this bug.
UPDATE
Found that the code below was "theming" the slider but when I removed it, it worked fine. What is a way i can keep the theme color and not get it to disappear?
[[UISlider appearance] setThumbTintColor:[UIColor colorWithRed:0/255.0f green:75/255.0f blue:152/255.0f alpha:1.0f]];
[[UISlider appearance] setMinimumTrackTintColor:[UIColor colorWithRed:164/255.0f green:75.0f blue:25/255.0f alpha:1.0f]];
[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
This is the well known bug in SetMaximumTrackTintColor.
Remove this line:
[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
and your app will work fine.
It is correct that this is a known bug. But have found a way to work around it so that you can still keep your theming:
[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
In UIViewController's where I use a slider, I set the maximumTrackTintColor in the viewDidLoad: method
- (void)viewDidLoad
{
[super viewDidLoad];
_slider.maximumTrackTintColor = [UISlider appearance].maximumTrackTintColor;
}
This works for me, so I wanted to share!
you can move the appearance changes into the viewDidLoad: function.
this way the appearance changes will only happened once.
- (void)viewDidLoad
{
// Appearance changes here
}
it works for me

UITabBar acts strange in iOS 7, how to fix it?

[[UITabBar appearance] setTintColor:[UIColor redColor]]; // for unselected items that are red
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; // for selected items that are green
Why is this code not working in iOS 7?
setTintColor works but only changes the "selected"-icon's color, not the unselected ones as it did in earlier iOS versions, which is weird ? setSelectedImageTintColor does'nt work at all anymore ? Is it realy not possible to color icons as you wish anymore?
Also the setSelectionIndicatorImage is not working as intended in the start of the app, what is happening in iOS 7?
Derp herp Apple, why ?
As of iOS 7 you have to use setBarTintColor: to set the background color, with setTintColor: now affecting the foreground color.
Answer from Adam Waite doesn't work. Method setFinishedSelectedImage under iOS7 ignores the selected image. You need to so it like this:
UITabBarItem *item1 = _tabBarController.tabBar.items[0];
item1.image = [[UIImage imageNamed:#"item1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [UIImage imageNamed:#"item1-selected"];
It's not tint, but you can do it with images:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"item_unselected.png"]];
This is a known issue in iOS 7. The tintColor is used for the selected tab image. The selectedImageTintColor is completely ignored. There is no way to tint unselected tab images.
See a discussion on the Apple Developer Forums https://devforums.apple.com/message/851126#851126 about this.
for (int i=0; i (smallerthen)arrayOfTabBarItems.count; i++) {
NSString *unselectedImageName = [NSString stringWithFormat:#"%#.png", arrayOfTabBarItems[i]];
NSString *selectedImageName = [NSString stringWithFormat:#"%#-pressed.png", arrayOfTabBarItems[i]];
[tabBarCtrl.tabBar.items[i] setFinishedSelectedImage:[UIImage imageNamed:selectedImageName] withFinishedUnselectedImage:[UIImage imageNamed:unselectedImageName]];
}
This worked for me.

Customizeappearance compatibility on others iOS

I did not see an answer to my question yet so I ask it :
I am currently using (void)customizeappearance to customize the design of my tabbar and navbar. Will that function restrain the use of my app to iOS5-based iPhone only ? If not, will my bars be seen the same in all devices ?
Thanks in advance.
Here is the method I am using :
- (void)customizeAppearance
{
UIImage *tabBackground = [[UIImage imageNamed:#"bg_tab"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"bg_tab_selected"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}
customizeappearance isn't a standard method. What methods are you actually calling to do the customisation?
If you are using methods like setBackgroundImage: or setTintColor: there's a good chance that your app will only run on iOS5 and will crash on iOS4. Post the methods you are using and I'll show you how to do it safely for iOS4.
Here's another answer that explains how to safely call iSO5-only customisation methods so that they won't crash on iOS4: iOS change tabbar item color is safe?
Here's an example of how to customise in a way that works on iOS 4 & 5: tabbar item image and selectedImage

Resources