ios - How to replicate a sentence with line breaks in between with an NSString? -


I was changing some old UIWebViews with UILabels and I realized that I had a string that looked like the following:

  NSString * eaten = You ate & lt; B & gt;% @ & lt; / B & gt; % From   

This sentence was being called as:

  NSString * warning = [NSString stringWithFormat: eaten, "cake", "janine "];   

It was displayed in this form:

  You were drawn from Jenin   

How do I do this Want to display. How do I add line breaks for NSString now?

I have tried the following and they do all the work:

  NSString * warning = [NSString stringWithFormat: @ "% @ \ R% @ \ r% @ ", Ate," cake "," jenin "]; NSString * Warning = [NSString stringWithFormat: @ "% @ \ n% @ \ n% @", eaten, "cake", "jenin"]; NSString * Warning = [NSString stringWithFormat: @ "% @ \ r \ n% @ \ r \ n% @", eaten, "cake", "jenin"];   

and

  self.warningLabel.numberOfLines = 0;   

But the output comes from:

  you have sent% @ to% @   

I here What to do?

Change either the straight (easy and clear) eaten string or between Add a new line to

  NSString * warning = [NSString stringWithFormat: eaten, @ "\ nCake \ n", @ "jenin"];   

If this is a variable, you have to use [NSString stringWithFormat: @ "\ n% @ \ n", middleVar] to create it Will be required.

Either way, this is a bad idea to get a format from a variable. Use a literal straight so that the compiler can check the logic number and type for you.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -