iOS 10 can no longer set barcolor and tint on MFMessageComposeViewController

后端 未结 4 561
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 01:50

Below code works on iOS version 9.x or less, for some reason this does not work if iOS 10

 if([MFMessageComposeViewController canSendText])
             {
               


        
4条回答
  •  离开以前
    2021-02-04 02:50

    Prior to iOS 10, I was using the appearance proxy for UINavigationBar, something like this:

    NSDictionary* titleAttribs = @{ NSForegroundColorAttributeName: [ColoursAndStyles sharedInstance].fontColourNavBarTitle,
                                    NSFontAttributeName: [ColoursAndStyles sharedInstance].fontNavbarBoldTitle };
    
    [[UINavigationBar appearance] setBarTintColor:[ColoursAndStyles sharedInstance].viewColourNavBarMain];
    [[UINavigationBar appearance] setTintColor:[ColoursAndStyles sharedInstance].viewColourNavBarTint];
    [[UINavigationBar appearance] setTitleTextAttributes:titleAttribs];
    

    This covered my use of MFMessageComposeViewController, with setTitleTextAttributes taking care of the text colour of the title/caption.

    With iOS 10, I'm using the following work around. Just before I present the MFMessageComposeViewController, I change the title text attributes. E.g.:

    - (void)sendTap:(id)s
    {
        // some code...
    
        NSDictionary* newTitleAttribs = @{ NSForegroundColorAttributeName: [ColoursAndStyles sharedInstance].fontColourTitleStrip,
                                           NSFontAttributeName: [ColoursAndStyles sharedInstance].fontNavbarBoldTitle };
    
        [[UINavigationBar appearance] setTitleTextAttributes:newTitleAttribs];
    
        // present the MFMessageComposeViewController...
    }
    

    And then set things back to how I want them for the rest of the app, when the MFMessageComposeViewController finishes, e.g.:

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    {
        NSDictionary* titleAttribs = @{ NSForegroundColorAttributeName: [ColoursAndStyles sharedInstance].fontColourNavBarTitle,
                                        NSFontAttributeName: [ColoursAndStyles sharedInstance].fontNavbarBoldTitle };
    
        [[UINavigationBar appearance] setTitleTextAttributes:titleAttribs];
    
        // some code...
    
        [controller dismissViewControllerAnimated:YES completion:^{
            // some code...
        }];
    }
    

提交回复
热议问题