hsusmita / ResponsiveLabel

MIT License
218 stars 36 forks source link

Read more and Read less issue. #28

Closed jpatel956 closed 8 years ago

jpatel956 commented 8 years ago

Actually i am using your library to expand/collapse UILabel in UITableViewCell. but some times when i click on "Read more" the UILabel is expand but not showing "Read less" label. so can you please help me to short out my issue. it is batter if you provide demo. here is my code that has been written in "cellForRowAtIndexPath" ..

        __block  NSString *str =mutArrEventList[indexPath.row][@"event_desc"];
        PatternTapResponder tap = ^(NSString *string) {
            NSLog(@"Tap on truncation text");

            if (![arrayOfExpandIndexPaths containsObject:indexPath]) {
                [arrayOfExpandIndexPaths addObject:indexPath];
            }

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
            });

        };

        if (![arrayOfExpandIndexPaths containsObject:indexPath]) {

             NSString *expansionToken = @"...Read more";

            NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:expansionToken attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:cell.lblDesc.font,RLTapResponderAttributeName:tap}];
            [cell.lblDesc setAttributedTruncationToken:attribString];

            cell.lblDesc.numberOfLines = 3;
            [cell.lblDesc setText:str withTruncation:YES];
        }
        else{

            NSString *expansionToken = @" Read less";

            NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:expansionToken attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:cell.lblDesc.font,RLTapResponderAttributeName:tap}];
            [cell.lblDesc setAttributedTruncationToken:attribString];

            cell.lblDesc.numberOfLines = 0;
            [cell.lblDesc setText:str withTruncation:NO];
            cell.lblDesc.customTruncationEnabled = YES;
        }
hsusmita commented 8 years ago

@jpatel956 Do you mean when you tap "Read More", the label gets expanded, but the text is truncated? Can you post a screenshot?

jpatel956 commented 8 years ago

@hsusmita , No actually i want to said that "Read more" and "Read less" is not working properly while i used in "cellForRowAtIndexPath". so can you provide me demo that used this library for showing content in UITableView.

hsusmita commented 8 years ago

Download the demo project. It has an example with tableview.

jpatel956 commented 8 years ago

@hsusmita , ohh sorry i forgot to see. i just integrate your library thorough cocoa pod and trying.