The
previous project
ended with a static string of HTML in a
UIWebView
.
NSString *html = /* etc. */; [webView loadHTMLString: html baseURL: nil];The following are examples of HTML created dynamically.
for
loop we saw in the first
array example.
“Pack my box” is a
pangram.
Change the orientation in the
Info.plist
file and the
shouldAutorotateToInterfaceOrientation:
method of the view controller back to portrait.
NSMutableString *html = [NSMutableString stringWithCapacity: 0]; SEL sel = @selector(caseInsensitiveCompare:); for (NSString *family in [[UIFont familyNames] sortedArrayUsingSelector: sel]) { [html appendFormat: @"<SPAN STYLE = \"font-family: %@;\">%@\n" "<BR>Pack my box with five dozen liqueur jugs.</SPAN><BR><BR>\n", family, family]; } html = [NSString stringWithFormat: @"<HTML>\n" "<HEAD>\n" "<META " "NAME = \"viewport\" " "CONTENT = \"initial-scale = 1.0, width = device-width\">\n" "</HEAD>\n\n" "<BODY>%@</BODY>\n" "</HTML>\n", html ];
for
loops:
NSMutableString *html = [NSMutableString stringWithCapacity: 0]; SEL sel = @selector(caseInsensitiveCompare:); for (NSString *family in [[UIFont familyNames] sortedArrayUsingSelector: sel]) { [html appendFormat: @"<SPAN STYLE = \"font-family: %@;\">%@</SPAN><BR>\n", family, family]; for (NSString *font in [UIFont fontNamesForFamilyName: family]) { [html appendFormat: @"<FONT FACE = \"%@\">%@</FONT><BR>\n", font, font]; } [html appendString: @"<BR>\n"]; } html = [NSString stringWithFormat: @"<HTML>\n" "<HEAD>\n" "<META " "NAME = \"viewport\" " "CONTENT = \"initial-scale = 1.0, width = device-width\">\n" "</HEAD>\n\n" "<BODY>%@</BODY>\n" "</HTML>\n", html ];
%04X
prints an integer as a minimum of four hexadecimal digits,
padded if necessary with leading zeroes.
For Arabic, loop from
\u0621
to
\u063A
inclusive.
NSMutableString *html = [NSMutableString stringWithCapacity: 0]; for (NSUInteger u = 0x05D0; u <= 0x05EA; ++u) { //aleph to tav inclusive [html appendFormat: @"&#x%04X;", u]; }