I am creating a report & printing the same on a UITextView.My report has some titles and there respective subtitles. I am printing 1st title then its subtitle & then second title and its subtitle and so on. I want different font and font sizes for the titles and subtitles. B开发者_如何学编程ut the problem is the text field always prints the last subtitle.If any one know solution to this problem,let me know.
Here is what i have dome in my .m file
- (void) printData {
// data is UITextView object
[data setFont:[UIFont fontWithName:@"Helvetica" size:15]];
NSString *title = @"TITLE" ;
data.text = title;
[data setFont:[UIFont fontWithName:@"Arial" size:15]];
NSString *subtitle = @"SUBTITLE" ;
data.text = subtitle;
}
First of all I would Use UITextView
instead of UITextField
, as it is build for long text.
If you just keep calling the method text of either UITextField
or UITextView
, the currently residing text will be replaced with your last text. To avoid that you have to append new text to the text that is already residing in the UITextField
or UITextView
.
NSString *appendThisText = @"subtitle";
self.myTextView.text=[NSString stringWithFormat:@"%@%@", self.myTextView.text, appendThisText];
As for the fonts. The font property applies to the entire UITextField
and UITextView
content.
What you could do in your case is to use UIWebView
and render your text using HTML.
Another way:
[myTextView setText:[myTextView.text stringByAppendingString:@"my string"]];
Or with a \n line break:
[myTextView setText:[myTextView.text stringByAppendingString:@"\nMy string"]];
精彩评论