The data is coming from parser, if the text is more than 120 char then it should append "...ReadMore" just like facebook. I have got the code for appending text, but dont know how to make clickable link. I'm using Swift Languange.
if cell!.bhikmangaTextlbl!.text!.utf16Count >= 120
{
var abc : String = (cell!.bhikmangaTextlbl!.text! as
NSString).substringWithRange(NSRange(location: 0, length: 120))
abc += " ...ReadMore"
cell!.bhikmangaTextlbl!.text = abc
}
@Mihir Mehta, This is code i have implemented.
var bhikmangaTextlbl:UITextView?
if cell!.bhikmangaTextlbl!.text!.utf16Count >= 120
{
var abc : String = (cell!.bhikmangaTextlbl!.text! as NSString).substringWithRange(NSRange(location: 0, length: 120))
abc += "...ReadMore"
cell!.bhikmangaTextlbl!.text = abc
var attribs = [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont.systemFontOfSize(14.0)]
var attributedString: NSMutableAttributedString = NSMutableAttributedString(string: abc, attributes: attribs)
attributedString.addAttribute(NSLinkAttributeName, value: "...ReadMore", range: NSRange(location: 120, length: 11))
attributedString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.StyleSingle.rawValue, range: NSRange(location: 120, length: 11))
cell!.bhikmangaTextlbl!.attributedText = attributedString
}
//The function you said i have written here
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool
{
return true
}
You can use attributed string here ... and make some part of text clickable
here is Objective C code. You can write same for Swift
NSDictionary *attribs = @{
NSForegroundColorAttributeName: BODY_FONT_COLOR,
NSFontAttributeName: [UIFont fontWithName:FontHelvetica size:AppFont16]
};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:ACCIDENT_DETECTION_AUTOMATIC_TEXT attributes:attribs];
[attributedString addAttribute:NSLinkAttributeName
value:@"Accident detection"
range:[[attributedString string] rangeOfString:@"Read More"]];
NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: LINKS_FONT_COLOR,
NSUnderlineColorAttributeName: [UIColor clearColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)};
// assume that textView is a UITextView previously created (either by code or Interface Builder)
self.accidentDetectionText.linkTextAttributes = linkAttributes; // customizes the appearance of links
self.accidentDetectionText.attributedText = attributedString;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With