Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-15-2011, 04:34 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 2
gagvx290 is on a distinguished road
Default Strange UILabel

Hi,

I have got a bit of an issue with trying to get a line break to appear in a UILabel view. I have looked around on this forum and several other and found fixes for specific cases but none that seems to work for me.

I am using:

Code:
NSString *response = [NSString stringWithContentsOfURL:requestURL encoding:NSASCIIStringEncoding error:&error];
To hit my server which calls a php script that returns a string to my app. My app then uses:

Code:
NSArray *myArray = [[tableData objectAtIndex:row] componentsSeparatedByString:@"/484"];
to split the string that we returned into an array of smaller strings. I then set the text of a label to one of these smaller strings as follows:

Code:
[myLabel setText:[myArray objectsatIndex:0]];
The string stored in the array is definitely valid, and contains a "\n", and a "\r" just in case, but when I load the app it just displays the "\n" and "\r" as text and does not move to the next line.

If anyone has any idea why this is happening, or how I might be able to fix it, it would be much appreciated.

Thanks
gagvx290 is offline   Reply With Quote
Old 10-15-2011, 05:05 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by gagvx290 View Post
Hi,

I have got a bit of an issue with trying to get a line break to appear in a UILabel view. I have looked around on this forum and several other and found fixes for specific cases but none that seems to work for me.

I am using:

Code:
NSString *response = [NSString stringWithContentsOfURL:requestURL encoding:NSASCIIStringEncoding error:&error];
To hit my server which calls a php script that returns a string to my app. My app then uses:

Code:
NSArray *myArray = [[tableData objectAtIndex:row] componentsSeparatedByString:@"/484"];
to split the string that we returned into an array of smaller strings. I then set the text of a label to one of these smaller strings as follows:

Code:
[myLabel setText:[myArray objectsatIndex:0]];
The string stored in the array is definitely valid, and contains a "\n", and a "\r" just in case, but when I load the app it just displays the "\n" and "\r" as text and does not move to the next line.

If anyone has any idea why this is happening, or how I might be able to fix it, it would be much appreciated.

Thanks

This is from the Xcode documentation on UILabel:

Quote:
numberOfLines
The maximum number of lines to use for rendering text.

@property(nonatomic) NSInteger numberOfLines
Discussion
This property controls the maximum number of lines to use in order to fit the label’s text into its bounding rectangle. The default value for this property is 1. To remove any maximum limit, and use as many lines as needed, set the value of this property to 0.

If you constrain your text using this property, any text that does not fit within the maximum number of lines and inside the bounding rectangle of the label is truncated using the appropriate line break mode.

When the receiver is resized using the sizeToFit method, resizing takes into account the value stored in this property. For example, if this property is set to 3, the sizeToFit method resizes the receiver so that it is big enough to display three lines of text.

The documentation is a wonderful thing.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 10-15-2011, 05:53 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 2
gagvx290 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
This is from the Xcode documentation on UILabel:
The documentation is a wonderful thing.
Thanks, but I have numberOfLines set to 0, and my label quite happily wraps onto multiple lines so that it fits into the view. The problem is with wanting to add line breaks using the "\n" character at a user defined point within the text that is in the label. Setting this property does not seem to help with this..?
gagvx290 is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, iphone, label, line break, uilabel

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
15 members and 390 guests
13dario13, 7twenty7, buggen, eski, EvilElf, glenn_sayers, j.b.rajesh@gmail.com, LunarMoon, morterbaher, n00b, QuantumDoja, sacha1996, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0