Цвет фона панели MFMailComposeViewController не изменяется в iOS7
Я пытаюсь изменить цвет фона MFMailComposeViewController
в iOS7, но я не могу заставить его работать.
Я использую следующий снимок:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if([picker.navigationBar respondsToSelector:@selector(barTintColor)]) {
// iOS7
picker.navigationBar.barTintColor = READER_NAVIGATION_BAR_BACKGROUND_COLOR;
// Set back button arrow color
[picker.navigationBar setTintColor:READER_NAVIGATION_BAR_BACK_BUTTON_ARROW_COLOR];
// Set Navigation Bar Title Color
[picker.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:READER_NAVIGATION_BAR_TITLE_NORMAL_FONT_COLOR forKey:UITextAttributeTextColor]];
// Set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:READER_NAVIGATION_BAR_BUTTONS_FONT_COLOR, UITextAttributeTextColor,nil] forState:UIControlStateNormal];
}
Кто-нибудь знает, как изменить цвет bakcground MFMailComposeViewController
в iOS7?
Ответы
Ответ 1
попробуйте это. работал на меня.
MFMailComposeViewController* myailViewController = [[MFMailComposeViewController alloc] init];
// set other attributes of mailcomposer here.
myMailViewController.mailComposeDelegate = self;
[myMailViewController.navigationBar setTintColor:[UIColor whiteColor]];
[self presentViewController:myMmailViewController animated:YES completion:nil];
Ответ 2
Трюк здесь состоит в том, чтобы вызвать "методы внешнего вида", такие как
[UINavigationBar appearance].barTintColor = [UIColor whiteColor];
[UINavigationBar appearance].tintColor = [UIColor redColor];
ПЕРЕД вызовом
[[MFMailComposeViewController alloc] init];
Таким образом, цветовая схема будет применена к почтовому композитору.
Он может быть возвращен к значениям по умолчанию в mailComposeController:didFinishWithResult:
Ответ 3
Решение Swift 3:
extension MFMailComposeViewController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
}
open override func viewDidLoad() {
super.viewDidLoad()
navigationBar.isTranslucent = false
navigationBar.isOpaque = false
navigationBar.barTintColor = UIColor.white
navigationBar.tintColor = UIColor.white
}
}
Ответ 4
Для iOS8:
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
или
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
Ответ 5
попробуйте это, но одна вещь BarTintColor доступна только для iOS7
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
Этот цвет сделан полупрозрачным по умолчанию, если вы не установите для свойства полупрозрачности значение NO.
или попробуйте эту ссылку, вам будет более полезно
Изменение цвета панели инструментов MFMailComposeViewController
Ответ 6
Попробуйте использовать следующий код
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
// Your usual code follows here ......
Ответ 7
@SoftDesigner ответ:
Начиная с iOS 9:
[UINavigationBar appearance].tintColor = yourFavoriteColor;
не работает в MFMailComposeViewController.
Остальная часть ответа работает (я использовал его), но насколько я могу судить, вы застряли в цветах Apple для кнопок панели навигации.
Надеюсь, это спасет кого-то еще от тоски.
Ответ 8
Сначала введите MFMailComposeViewController
, затем измените его tintColor
[self presentViewController:emailDialog animated:TRUE completion:nil];
[[UINavigationBar appearance] setBackgroundImage:nil
forBarPosition:UIBarPositionTopAttached
barMetrics:UIBarMetricsDefault];
Ответ 9
У меня была проблема, которая помешала мне установить цвет фона. Оказывается, у меня был другой код в другом месте, устанавливающий фоновое изображение на [UIImage new].
В следующем коде исправлено:
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:nil];