Need help with UIText - iphone

I'm trying to make it so that the text displays like
Alabama
Alaska
Arkansas
and so on.
I mostly just need help on how to make it go to the next line of text
lblText.text = #"Alabama:";
i tried doing #"Alabama:"
#"alaska:";
but it didn't work.
Any thoughts?

Use UITextView
UITextView *textView;
.......
textView.text = #"Alabama \nAlaska \nArkansas";

If you don't want to use UITextView as recommended, you can continue to use your UILabel and set lblText.numberOfLines = 0; to make it multiline.
You'll still need to take the previous advice and put a \n between each State Name.

Related

Assign Some Text to particular line in UITextView Programmatically

I create an instance of UITextView programmatically. I want to assign some text to particular line in UITextView programmatically. Here is my code to create UITextView.
UITextView *textView =[[UITextView alloc]init];
textView.frame=CGRectMake(0,0,282,210);
[textView setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:textView];
For example I want to add some text to particular line (at the end of line 5).
Programmatically, how is it possible to do this?
UITextView *textView =[[UITextView alloc]init];
textView.frame=CGRectMake(0,0,282,210);
textView.text = #"xxxxxx";
...
You can't edit lines directly in the text view because the number of lines depends on the content size and the size of the font.
Check this question as a reference:
How to Read Number of lines in UITextView
You could do some calculation to determine where to insert the text, but I'm nor sure if that's the best way to go around. There is probably a better way to accomplish what you are trying to do.
you can use the following:
NSString *str=yourTextview.text;
[str stringByAppendingString:yourNewString];
Then add it to textview
yourTextView.text=str;
check it and let me know if any clarification you need

UITextView or UIWebView: How to display pages of a simple editable TXT file

All I want to have is a full-screen simple text editor. However, I don't want the scrolling component, but rather let the user flick through the pages (instead of scrolling). So I need to import or open a TXT and then format it by braking it down (e.g. by dividing its contents to 10 lines per screen/page).
My question is how I will display the txt? UITextView is scrollable (even though I can disable this in IB)... I did not find any method for UIWebView to let it format my contents on different 'pages' or screens.
Where will I need to start? Ideally I'd need some sample code. All the samples for UIWebView do not tell me anything about how to format editable text on several pages.
So all I really want is an UITextView which is not scrollable and opens up a new page/screen if I run out of space on the first page/screen.
Thanks for any help to get me started.
first thing first ...... there is no particular method to achieve this
1.You need to break your single string into multiple strings, to do that you can use
int pageNumber; // suppose this keep track of on what page you are
int count; //suppose this keep track of how long string your one screen support
NSString* completeString; //suppose this is your string
NSRange range = NSMakeRange(pageNumber * count, count);
NSString* temp = [completeString substringWithRange:range];
2.Now instead of using UITextView (if you don't want user interaction ) you should use UILable
just change the property of UILabel (this one is of your interest)
UILabel* myLabel; //suppose this is that label
myLabel.numberOfLines = 0; //this will chage your label to go multyline.
You should be able to achieve this by putting your UITextView into a UIScrollView and setting pagingEnabled on the UIScrollView to YES.

UITableview to autowrap long text

How can I get a UITableView to automatically wrap text which is longer than the width of the cell?
You need to dynamically determine the height of the cell, and set your label so that it autosizes itself. There's a fairly comprehensive explanation here: http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
Set the "setNumberOfLines" property of the label to wrap the text to required number of lines. If you don't want the .... at the end of the text if it is too long then
label.lineBreakMode = UILineBreakModeWordWrap;
or if you want to show the ... after the text then don't use the above code.
All the best.
See the options for the lineBreakMode of the UILabel inside the UITableViewCell here.
hth
–f

Custom iPad 10-key popover possible

and thanks for your responses in advance.
I have been looking around for the possibility of having a 10-key, numeric only, input available when a user clicks on certain fields that do not require the use of the full size keyboard.
I know that popovers can properly display custom types of input, but does anyone know if there is a way for a standard 10-keypad to display in a popover? And if so, can you point me in the right direction.
Again, thanks in advance.
-Rick
You don't need to use popover if you try to enter numeric value in a UITextField/UITextView.
You can replace the keyboard by your own view.
You just do :
[yourTextField setInputView:myInputView];
You can have a look at KeyboardAccessory sample from apple
http://developer.apple.com/iphone/library/samplecode/KeyboardAccessory/Introduction/Intro.html
In this example, they provide an accessory view to the input view but if you modify the code and set inputView instead of inputViewAccessory, you should be able to do what you need.
If you use a UITextView, you can append text where the carret is with the following code:
NSMutableString *text = [textView.text mutableCopy];
NSRange selectedRange = textView.selectedRange;
[text replaceCharactersInRange:selectedRange withString:#"\n"];
textView.text = text;
If you use a UITextField, it seems you can only append text at the end of the string (no mean to retrieve carret position).

One label, two different fonts?

I need to format text in a label like this:
username: some text from this user. This will
create additional lines of text that will go
on and on and on.
Where "username" is bold. This will go into a UILabel, which is in a custom table cell. Is there a way to get this type of layout?
For this relatively simple case, you might be able to fake it. Have one label with the bold username, and another label with the plain text in the same position. Insert enough spaces before the plain text to leave room for the username. You can use UIStringDrawing methods to measure the bold text and the spaces.
CGSize usernameSize = [theUsername sizeWithFont:theBoldUsernameFont];
CGSize spaceSize = [#" " sizeWithFont:thePlainCommentFont];
NSString *indentedComment = [NSString stringWithFormat:#"%*s%#" , (int)ceil( usernameSize.width / spaceSize.width ) , "" , theComment];
If you use plain UILabel it's not available. Use two labels for this task.
You need to use either a UIWebView or CoreText to do this kind of advanced text layout. A web view has a lot of overhead but is most flexible and you can't use it effectively in a UITableView cell. CoreText is low level and not that well documented. You could ditch the table view and just lay out the table with CSS and HTML in the web view, which is how I do it.
You can still use a UITableViewCell but have the cell use a UIWebView subview. Set up a custom cell subclass with a clever setter method that allows you to send nsstrings to the method with turns those into a pretty formatted view.