How to display a separate text in UITexview other than its text?
In my app i have to display some other text with the text of UITextView i text view. For ex: I want to display the today's date first and then i will start adding the content on UITextView. all the data is coming from xml's and i have different NSSet's containing thes开发者_高级运维e values.
Thanks
Very simple. If you have text in your text view and than create 1 date Variable and convert it to NSString. And use following assignment to have your goal finished.
yourTextView.text = [NSString stringWithFormat:"%@ %@",yourStringDateVariable,yourTextView.text];
Does this make sense ?
Does the text you add need to not be editable? If it doesn't, then just set the text property of the UITextView with your default text, and you are done.
If you need the user to not be able to get rid of / change your text, then when you set the default text, store the length of the string in an instance variable. Set a custom object as the UITextView's delegate. After that, use the three methods
– textView:shouldChangeTextInRange:replacementText:
– textViewDidChange:
– textViewDidChangeSelection:
to make sure the user doesn't change the original text.
For more info on those delegate methods, check out the UITextViewDelegate class reference
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html#//apple_ref/occ/intf/UITextViewDelegate
Is your question as simple as "String Concatenation" ??
[NSString stringWithFormat:@"%@/%@/%@", three, two, one];
精彩评论