gpt4 book ai didi

ios - TTTAttributedLabel 的链接点击颜色

转载 作者:IT王子 更新时间:2023-10-29 08:13:19 26 4
gpt4 key购买 nike

我在我的项目中使用 TTTAttributedLabel。我通过修改链接属性成功地更改了我创建的任何链接的默认颜色和下划线。

NSArray *pKeys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,
(id)kCTUnderlineStyleAttributeName
, nil];

NSArray *pObjects = [[NSArray alloc] initWithObjects:pAlertColor,[NSNumber numberWithInt:
kCTUnderlineStyleNone], nil];

NSDictionary *pLinkAttributes = [[NSDictionary alloc] initWithObjects:pObjects
forKeys:pKeys];

self.alertMessage.linkAttributes = pLinkAttributes;
self.alertMessage.activeLinkAttributes = pLinkAttributes;

但是,我注意到当我点击链接时,它会瞬间变成红色,就像点击任何其他链接时一样。我需要改变这种颜色。关于如何做到这一点的任何线索?

最佳答案

Swift 2 解决方案:

enter image description here

具体需要设置activeLinkAttributes,见下例:

private func subscriptionNoticeWithDelegate(delegate:TTTAttributedLabelDelegate) -> TTTAttributedLabel {
let subscriptionNotice:String = "To turn on all notifications, subscribe to our monthly " +
"service ($0.99/month). If you have already subscribed, please restore your purchase."

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = 1.2

let subscriptionNoticeAttributedString = NSAttributedString(string:subscriptionNotice, attributes: [
NSFontAttributeName: UIFont(name:"HelveticaNeue-Light", size:15)!,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName: UIColor.grayColor().CGColor,
])
let subscriptionNoticeLinkAttributes = [
NSForegroundColorAttributeName: UIColor.grayColor(),
NSUnderlineStyleAttributeName: NSNumber(bool:true),
]
let subscriptionNoticeActiveLinkAttributes = [
NSForegroundColorAttributeName: UIColor.grayColor().colorWithAlphaComponent(0.80),
NSUnderlineStyleAttributeName: NSNumber(bool:true),
]

let subscriptionNoticeLabel:TTTAttributedLabel = TTTAttributedLabel(frame:CGRectZero)
subscriptionNoticeLabel.delegate = delegate
subscriptionNoticeLabel.numberOfLines = 0
subscriptionNoticeLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
subscriptionNoticeLabel.textInsets = UIEdgeInsets(top:10, left:15, bottom:0, right:15)
subscriptionNoticeLabel.setText(subscriptionNoticeAttributedString)
subscriptionNoticeLabel.linkAttributes = subscriptionNoticeLinkAttributes
subscriptionNoticeLabel.activeLinkAttributes = subscriptionNoticeActiveLinkAttributes

let subscribeLinkRange = (subscriptionNotice as NSString).rangeOfString("subscribe")
let subscribeURL = NSURL(string:kSubscriptionNoticeSubscribeURL)!
subscriptionNoticeLabel.addLinkToURL(subscribeURL, withRange:subscribeLinkRange)

let restoreLinkRange = (subscriptionNotice as NSString).rangeOfString("restore")
let restoreURL = NSURL(string:kSubscriptionNoticeRestoreURL)!
subscriptionNoticeLabel.addLinkToURL(restoreURL, withRange:restoreLinkRange)

return subscriptionNoticeLabel
}

关于ios - TTTAttributedLabel 的链接点击颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28411834/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com