Exercises 2 and 3 of the
previous project
ended with a
String
containing a page of HTML displayed in a
UIWebView
.
let html: String = /* etc. */; webView.loadHTMLString(html, baseURL: nil);
The following are examples of HTML created dynamically.
application(_:didFinishLaunchingWithOptions:)
method of the application delegate of the
previous project.
for familyName in UIFont.familyNames() { print("\(familyName)"); }
Marion Copperplate Heiti SC Iowan Old Style Courier New etc.
See Closure Expressions.
var familyNames: [String] = UIFont.familyNames() as! [String]; familyNames.sort({$0 < $1}); //parentheses unnecessary for familyName in familyNames { print("\(familyName)"); }
for familyName in (UIFont.familyNames() as! [String]).sorted({$0 < $1}) { print("\(familyName)"); }
Academy Engraved LET Al Nile American Typewriter Apple Color Emoji Apple SD Gothic Neo
html
string as follows.
var html: String = ""; for familyName in (UIFont.familyNames() as! [String]).sorted({$0 < $1}) { html += "<BR><BR><SPAN STYLE = \"font-family: \(familyName);\">\(familyName)\n" + "<BR>Pack my box with five dozen liqueur jugs.</SPAN>\n"; } html = "<HTML>\n" + "<HEAD>\n" + "<META " + "NAME = \"viewport\" " + "CONTENT = \"initial-scale = 1.0, width = device-width\">\n" + "</HEAD>\n\n" + "<BODY>\(html)</BODY>\n" + "</HTML>\n"; print("\(html)"); webView.loadHTMLString(html, baseURL: nil);
<HTML> <HEAD> <META NAME = "viewport" CONTENT = "initial-scale = 1.0, width = device-width"> </HEAD> <BODY><BR><BR><SPAN STYLE = "font-family: Academy Engraved LET;">Academy Engraved LET <BR>Pack my box with five dozen liqueur jugs.</SPAN> <BR><BR><SPAN STYLE = "font-family: Al Nile;">Al Nile <BR>Pack my box with five dozen liqueur jugs.</SPAN> <BR><BR><SPAN STYLE = "font-family: American Typewriter;">American Typewriter etc. </BODY> </HTML>
%04X
prints an integer as a minimum of four hexadecimal digits,
padded if necessary with leading zeroes.
For
Hebrew
(LANG = "HE"
),
loop from
0x05D0
to
0x05EA
inclusive.
For
Arabic
(LANG = "AR"
),
loop from
0x0621
to
0x063A
inclusive.
For
Russian
(LANG = "RU"
),
loop from
0x0410
to
0x044F
inclusive.
var html: String = ""; for var i = 0x05D0; i <= 0x05EA; ++i { html += String(format: "%04X;", i); } html = "<HTML>\n" + "<HEAD>\n" + "<META " + "NAME = \"viewport\" " + "CONTENT = \"initial-scale = 1.0, width = device-width\">\n" + "</HEAD>\n\n" + "<BODY STYLE = \"text-align: right;\"><BR>\n" + "<SPAN LANG = \"HE\" STYLE = \"font-size: 200%;\">\(html)</SPAN>\n" + "</BODY>\n" + "</HTML>\n"; print("\(html)"); webView.loadHTMLString(html, baseURL: nil);
<HTML> <HEAD> <META NAME = "viewport" CONTENT = "initial-scale = 1.0, width = device-width"> </HEAD> <BODY STYLE = "text-align: right;"><BR> <SPAN LANG = "HE" STYLE = "font-size: 200%;">אבגדהוזחטיךכלםמןנסעףפץצקרשת</SPAN> </BODY> </HTML>