2011-10-03 11 views
12

Esiste un modo per dichiarare uno NSString in più righe? Voglio scrivere il codice HTML e memorizzarlo in uno NSString, e in più righe de codice sarà più leggibile. Voglio fare qualcosa di simile:Dichiarare una NSString su più righe

NSString *html = @"\<html\>" 
+ @"\<head\>" 
+ @"\<title\>The Title of the web\</title\>" 
+ @"\</head\>" 
+ @"\<body\>" 
[...] 
+1

duplicati di http://stackoverflow.com/questions/797318/how-to-split-a-string- letteral-across-multiple-lines-in-c-objective-c – rid

risposta

38

Questo è un esempio:

NSString *html = [NSString stringWithFormat:@"<html> \n" 
          "<head> \n" 
          "<style type=\"text/css\"> \n" 
          "body {font-family: \"%@\"; font-size: %dpx;}\n" 
          "img {max-width: 300px; width: auto; height: auto;}\n" 
          "</style> \n" 
          "</head> \n" 
          "<body><h1>%@</h1>%@</body> \n" 
          "</html>", @"helvetica", 16, [item objectForKey:@"title"], [item objectForKey:@"content:encoded"]]; 
+0

Grazie per il codice! – Jimmy