How to change buttons in MFMailComposeViewController?

前端 未结 3 1745
Happy的楠姐
Happy的楠姐 2021-01-17 12:31

In my app I am using the MFMailComposeViewController. I have placed a back and Done button in the title bar. I have the title bar to be in black co

相关标签:
3条回答
  • 2021-01-17 12:51

    I followed this to add custom buttons replacing the standard cancel and send buttons:

    // Fetch the UINavigationItem object of the nav bar
    UINavigationItem *mailVCNavItem = [mailVC.navigationBar.items objectAtIndex:0];
    
    // Get the old bar button item to fetch the action and target.
    UIBarButtonItem *oldCancelBarButton = [mailVCNavItem leftBarButtonItem];
    
    // Create your new custom bar button item. 
    // In my case I have UIButton with image set as a custom view within a bar button item.
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"backButton.png"] forState:UIControlStateNormal];
    [backButton addTarget:oldCancelBarButton.target action:oldCancelBarButton.action forControlEvents:UIControlEventTouchUpInside];
    backButton.bounds = CGRectMake(0.0, 0.0, 40.0, 25.0);
    [[barButtonItems objectAtIndex:0] setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:backButton]];
    

    Unfortunately I wasn't able to replace the Send button.

    It just renders the button useless.

    0 讨论(0)
  • 2021-01-17 13:04

    For Swift (I am using Swift 1.2)

    var mc: MFMailComposeViewController = MFMailComposeViewController()
    mc.mailComposeDelegate = self
    mc.setSubject(emailTitle)
    mc.setToRecipients(toRecipients)
    mc.navigationBar.tintColor = UIColor.blackColor()
    
    0 讨论(0)
  • 2021-01-17 13:07

    You first have to change the button style: barButton.style = UIBarButtonItemStyleBordered;

    Afterwards, the color of the navigation bar buttons can be changed with the following code:

    [[mailComposer navigationBar] setTintColor:[UIColor blackColor]];
    
    0 讨论(0)
提交回复
热议问题