Generate the page of HTML dynamically

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.

  1. Replace the above string with one created with the 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
    	];
    
  2. Loop through the names of the fonts in each family with nested 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
    	];
    
  3. Loop through all the letters in a foreign alphabet. See the Unicode code charts. The format %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];
    	}