Hiren
Hiren

Reputation: 686

How can i limit and expand the content of UITextView?

I am facing a problem regarding UITextView content in which I am getting data from the server and if the content is large then I should display limited content and then by the use of a "Load More" titled button I can load additional content from the server.

How can I do this?

Upvotes: 0

Views: 153

Answers (3)

Mrunal
Mrunal

Reputation: 14118

As Yusuf mentioned, it should be done at server side. Here are the base steps:

  • In request send one param, (int fromIndex), initially it will be 0, for next request it will be text length. So that service side, it requires to get substring which starts from the length value.
  • In response send two params (string subString, int fullLength). So now append your textview.text with subString.
  • Now check,

textView.text.length < fullLenght,

then display "Show More" button which will hit the service request again.

  • Next time

fromIndex = textView.text.length

This is the base logic. Apply this as per your service environment.

Hope this will help you.

Upvotes: 0

Yusuf terzi
Yusuf terzi

Reputation: 186

You can do this at server side. If data is big set a property of data true. On client side use this property for more button.

Upvotes: 1

Janmenjaya
Janmenjaya

Reputation: 4163

You fetch the total content, check its length. If It would be greater than the limited content then show the title button, and on click of button re-frame the textView and show the total content. Here I assume 200 characters can be contained in the textview having height 100

Example

UITextView *txtVw = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[self.view addSubview:txtVw];


NSString *strContent = @"content from server";
if (strContent.length > 200) {
    NSLog(@"Write your code to show the MORE title button");
}
else
{
    NSLog(@"Show the text");
}

Upvotes: 0

Related Questions