Search code examples
iosmfmailcomposeviewcontroller

Launching MFMailComposeViewController cuts off recipient text


I am using Apple's sample code for the MessageUI and MFMailComposeViewControllerDelegate, and mostly it works great. But for some reason when I implement it, the text in the recipient fields appears out of alignment with the field labels, and you can only see half of the cursor and half of the text while typing. Once you've typed the addresses and exited the field, the text is completely visible, though still out of alignment with the labels. I have looked at other apps' implementations of the MessageUI, and they do not seem to have this problem. has anyone seen this problem and found a solution?

Below is code:

-(void)displayComposerSheet 
{
   MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];  
   picker.mailComposeDelegate = self;

   [picker setSubject:@"Data"];

   // Set up recipients
   NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

   [picker setToRecipients:toRecipients];

   // Attach an attachment to the email
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *csvFile = [documentsDirectory stringByAppendingPathComponent:@"myFile.csv"];
   NSData *myData = [NSData dataWithContentsOfFile:csvFile];
   NSString *filename = @"myFile.csv";
   [picker addAttachmentData:myData mimeType:@"text/csv" fileName:filename];

   // Fill out the email body text
   NSString *emailBody = @"Attached is the data";
   [picker setMessageBody:emailBody isHTML:NO];

   [self presentModalViewController:picker animated:YES];

}

The problem occurs in both the simulator and on device.


Solution

  • Probably, you've got a custom UITextField in your app and have some custom code in - (CGRect)textRectForBounds:(CGRect)bounds. If you'd like to have some category for UITextField class, try to put your specific code directly to the class where you using that instead of using category, which affects all textfields in your app, even in MFMailComposeViewController