The links pasted by users are very long and contain "http://" etc and hence I want to restrict the length of links and show only the main website name or a bit more than that.
Example:
Link pasted by user:
Link I want to display in the label: www.androidpolice.com/2015/08/...
Is there any way to do it?
I searched and found something called attributedTruncationToken but I didn't understand much and I think it's related to truncation at the end of line.
I don't use TTTAttributeLabel but this answer is for all the future question seekers that are struggling to create a URL shortener without 3rd party API's.
Simply use a
NSMutableAttributedString
and pass into aUIDataDetectorTypeLink
capable object:Let's say your user inputs a link or passes a string entirely:
We can easily extract the text using commonly frequented methods:
Where
[self createHyperLinkForURL:newURL withName:shortenedName];