Incorrect alignment when sending ASCII Art via SMS and Email in iPhone SDK
In my iPhone app, I have ASCII art, which I am sharing via email and SMS.
I have inserted the ASCII art into the Sqlite database along with the newline character and spaces.
Problem is when I send them through SMS and Email, the whole ASCII art comes in left alignment and spacing between characters is lost.
ASCII Art fetched in Label in my app is as below
Same ASCII Art when inserted to Email API (MFMailComposeViewController) is as below
Same ASCII A开发者_JS百科rt when inserted to SMS API (MFMessageComposeViewController) is as below
How to maintain the spaces? How to make the ASCII art look proper in Mail as well as SMS API View?
Maybe it's because of the font. If you use in your App courier new then each space would have the same gap like a normal character but in other fonts they are not the same. You can try and replace each space with double space perhaps it will look nice again.
You can set html to your MFMailComposeViewController
so to force spaces you can use ' '
or ' '
instead of ' '
Also, before showing your composer view you can change an attribute to display html ([mailComposer setMessageBody:myHtmlString isHTML:YES];
) where myHtmlString
represent this:
<html>
<head>
<style type="text/css">
body {font-family: courier new;
font-size: 10pt;
color: 00000;
}
</style>
</head>
<body>
your ascii art here
</body>
</html>
To expand on my second advice, replace each space with double space:
[asciiArtString stringByReplacingOccurrencesOfString:@" " withString:@" "];
精彩评论