4

I am using TTTAttributedLabel in my Project. All i have a large text which i have to show in uilabel. After certain number of lines, "more" text should be there if text get truncated. All things are working fine but when i am clicking on the link,the link seems to be added to the characters immediate before the truncation text at times - so tapping on the truncation text doesn't do anything. Can anyone please help me as i need this to be solve as early as possible.

let truncatedStringColour = [
    NSForegroundColorAttributeName: UIColor(red: 142.0/255.0, green: 59.0/255.0, blue: 84.0/255.0, alpha: 1.0),
    NSFontAttributeName: UIFont(name: "DINRoundOT", size: 17.0)!,
    NSLinkAttributeName : "link"
]

truncatedString = NSAttributedString(string: "...more", attributes: truncatedStringColour)

if let truncatStr = truncatedString {
    cell.lblDescription.attributedTruncationToken = truncatStr
}
pableiros
  • 14,932
  • 12
  • 99
  • 105
Aditya
  • 115
  • 3
  • 14
  • anyone has idea regarding this question? – Aditya Jun 06 '16 at 04:50
  • can you please make the question more understandable,as it is not cleared what you want say – Diksha Jun 06 '16 at 06:04
  • Please help i need to solve it asap.. – Aditya Jun 08 '16 at 14:25
  • Check which version you're using of `TTTAttributedLabel` (if you are using Cocoapods, check `Podfile`). They released 2.0.0 on May 10 which might have fixed your issue. – Edgar Jun 09 '16 at 07:31
  • @Edgar yes i am using the current version.But what problem i am facing is if the truncated text is at the end of the row,it is clickable fine but if it is at the middle of row, then it is not clickable. – Aditya Jun 09 '16 at 07:41
  • @Edgar I think when i am using \n in my attributed text and suppose "...more" comes just before \n then it result an issue.Then it is not clickable.Do you have an idea why it is happening? – Aditya Jun 09 '16 at 13:50
  • @Aditya, is it possible for you to embed your sample input in the control's example code to see if this is the problem at the control's end ? or it is specific to the project.. – NeverHopeless Jun 13 '16 at 07:31
  • @NeverHopeless yes i did that but its not working – Aditya Jun 13 '16 at 13:45
  • Have you tried setting the `cancelsTouchesInView` to false? – Mtoklitz113 Jun 14 '16 at 18:57
  • greetings sir, did you need to chat, you had created this room here: http://chat.stackoverflow.com/rooms/128803/room-for-aditya-and-drew – Drew Nov 23 '16 at 15:06

1 Answers1

0

Docs say:

TTTAttributedLabel can display both plain and attributed text: just pass an NSString or NSAttributedString to the setText: setter. Never assign to the attributedText property.

To resolve, set the label's text property instead of the attributed Text property.

Check this answer

You can use this to help you more.

Community
  • 1
  • 1
Mtoklitz113
  • 3,828
  • 3
  • 21
  • 40
  • yes i set the text property instead of attributed text property. But still it causes a problem. – Aditya Jun 15 '16 at 03:33
  • Have you added TTTAttributedLabelDelegate at the class where you are using the tableView datasource and delegate? – Mtoklitz113 Jun 15 '16 at 03:46
  • 1
    yes i have added there already. What happen is suppose 10 lines are there that need to be shown in label..and after 5 lines there is a \n\n so that after 2 lines 6th line start. So suppose at the end of line 5, i have truncated text "...more" , then it is not clickable. Means if i have continous text then it is working fine but if i have \n\n and just at the end of line5 truncation token there,then it fails.It is not getting clicked. – Aditya Jun 15 '16 at 07:48
  • Check this [Library](https://github.com/hsusmita/ResponsiveLabel/). Referenced from [here](http://stackoverflow.com/a/31827226/5654848). – Mtoklitz113 Jun 15 '16 at 07:58
  • I need this in swift. Similar to this i found one library in swift also, but that library has 1 restriction, if i show only 3 lines then that truncated text appears, but if i have to show more than 3 lines then that truncated text gets invisible. – Aditya Jun 15 '16 at 09:54
  • You can use [this](https://objectivec2swift.com/#/home/main) to convert objective C to swift code. I'm afraid this is all I could do for you. I've edited my **answer** which has helped you. Good luck! :) – Mtoklitz113 Jun 15 '16 at 12:53
  • I have tried with the convertor.But there are 133 errors...and not understandable..Can you please try to convert this in swift if possible? – Aditya Jun 15 '16 at 13:31