Change attributed color of text with IOS link
How do I change the color of the attribute text from blue to white?
When I click on the UITextView the application opens the url, I just need to change the color to white.
My code is in C #, but I think it can be easily converted to swift or objective-c.
I tried this path but it didn't work:
NSMutableAttributedString footerText = new NSMutableAttributedString(myFooterText, new UIStringAttributes
{
ForegroundColor = UIColor.White,
Link = new NSUrl(myLinkString)
});
//Set footer text
MyTextView.AttributedText = footerText;
+3
source to share
4 answers
Sample code snippet
UIStringAttributes attrHyperlink= new UIStringAttributes();
attrHyperlink.UnderlineStyle = NSUnderlineStyle.Single;
attrHyperlink.ForegroundColor = UIColor.Purple.CGColor;
NSMutableAttributedString attString = new NSMutableAttributedString(StringValue);
attString.AddAttributes(attrHyperlink, new NSRange(0,StringValue.Length));
MyTextView.AttributedText = attString;
try it
+3
source to share
Check this attribute line for link
NSString *str = @"Link";
NSMutableAttributedString *aStr = [[NSMutableAttributedString
alloc]initWithString:str attributes:nil];
[aStr addAttribute:NSLinkAttributeName value:@"Your Link here"
range:[str rangeOfString:@"Link"]];
[UITextView appearance].linkTextAttributes = @{ NSForegroundColorAttributeName : UIColor.redColor };
[self.text_View setAttributedText:aStr];
[self.text_View setTextAlignment:NSTextAlignmentNatural];
+2
source to share
See the image attached, I feel like you want something like this. Use the following code snippet. It works at my end
self.infoTextView.text = @"I am text. I am link.";
NSString *info = self.infoTextView.text;
NSRange commaRange = [info rangeOfString:@"I am link."];
NSMutableAttributedString *infoString = [[NSMutableAttributedString alloc] initWithString:info];
[infoString addAttribute: NSLinkAttributeName value: @"http://www.google.com" range: commaRange];
self.infoTextView.tintColor = [UIColor colorWithRed:255.0f/255.0f green:181.0f/255.0f blue:51.0f/255.0f alpha:1.0]; //link color
[infoString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:61.0/255.0 green:82.0/225.0 blue:96.0/255.0 alpha:1.0] range:(NSRange){0, [info length]}]; //original text color
[infoString addAttribute:NSFontAttributeName value:self.infoTextView.font range:(NSRange){0, [info length]}];
self.infoTextView.attributedText = infoString;
0
source to share