2011-10-03 11 views
12

¿Hay alguna forma de declarar NSString en varias líneas? Quiero escribir código HTML y almacenarlo en un NSString, y en varias líneas, el código será más legible. Quiero hacer algo como esto:Declarar un NSString en varias líneas

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

duplicados de http://stackoverflow.com/questions/797318/how-to-split-a-string- literal-across-multiple-lines-in-c-objective-c – rid

Respuesta

38

Este es un ejemplo:

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

¡Gracias por el código! – Jimmy

Cuestiones relacionadas