Liam Stockhomme
Liam Stockhomme

Reputation: 523

How to line break in NSString?

I've been searching for how to make a line break in an NSString, and I tried this solution: NSString with \n or line break which didn't work for me. When it rendered on the simulator it was still all one a single line.

I also found a website that said simply putting \n at the end of each sentence will start a new line, this didn't work either..

I want to have this on 5 lines, this is where I'm at (PS working with SKLableNode):

   instructions.text = [NSString stringWithFormat:@"TAP THE DOGS BEFORE THEY\nLEAVE THE SCREEN\nGAIN A POINT FOR EACH DOG TAPPED\nLOSE A POINT FOR EACH DOG LOST\n5 POINTS FOR SMALL DOGS"];

Can anyone seem to help me figure out how to properly have those on different lines?

Thanks in advance.

Upvotes: 1

Views: 1166

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130193

The problem isn't with your line breaks (you're doing it correctly), it's with SKLabelNode, which does not support multiple lines. There are however a number of open source replacements that have been made to support multiple lines. Here's one:

https://github.com/downrightsimple/DSMultilineLabelNode

Additionally, you aren't actually formatting your string so there's no need to use stringWithFormat: here. You can jus use the string literal instead.

instructions.text = @"TAP THE DOGS BEFORE THEY\nLEAVE THE SCREEN\nGAIN A POINT FOR EACH DOG TAPPED\nLOSE A POINT FOR EACH DOG LOST\n5 POINTS FOR SMALL DOGS";

Upvotes: 1

Related Questions