{
let title = “服务协议和隐私政策”
let linkDic = ["《服务协议》": "http://api.irainone.com/app/iop/register.html",
"《隐私政策》": "http://api.irainone.com/app/iop/register.html",]
let string = "\n\t服务协议和隐私政策:请你务必审慎阅读、充分理解“服务协议”和“隐私政策“各条款,包括但不限于:为了向你提供即时通讯、内容分享等服务,我们需要收集你的设备信息、 *** 作日志等个人信息、你可以在“设置”中管理你的授权。\n\t你可以阅读《服务协议》,《隐私政策》了解详细信息。如你同意,请点击“同意”开始接受我们的服务。"
let attributeString = NSMutableAttributedString(string: string)
//从文本0开始6个字符字体HelveticaNeue-Bold,16号
// attributeString.addAttribute(NSAttributedString.Key.font,
// value: UIFont(name: "HelveticaNeue-Bold", size: 16)!,
// range: NSMakeRange(0, 5))
let range1 = string.range(of: "《服务协议》")!
let location1 = string.distance(from: string.startIndex, to: range1.lowerBound)
//设置字体颜色
attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.hexColorWithAlpha(hexString: "#27B6F8"), range: NSMakeRange(location1, 6))
//paraStyle
// attributeString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paraStyle,
// range: NSMakeRange(location1, 6))
let range2 = string.range(of: "《隐私政策》")!
DDLog(range2)
let location2 = string.distance(from: string.startIndex, to: range2.lowerBound)
attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.hexColorWithAlpha(hexString: "#27B6F8"), range: NSMakeRange(location2, 6))
//paraStyle
// attributeString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paraStyle,
// range: NSMakeRange(location2, 6))
// attributeString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paraStyle,
// range: NSMakeRange(0, (string as NSString).length))
//attributeString.addAttribute(NSAttributedString.Key.link, value: "yonghuxieyi://", range: range)
// let range3 = string.range(of: "《权限使用规则》")!
// let location3 = string.distance(from: string.startIndex, to: range3.lowerBound)
// attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.hexColorWithAlpha(hexString: "#27B6F8"), range: NSMakeRange(location3, 8))
//设置文字背景颜色
// attributeString.addAttribute(NSAttributedString.Key.backgroundColor,
// value: UIColor.orange, range: NSMakeRange(0, 5))
// let attributedText = NSAttributedString.create(string, textTaps: Array(linkDic.keys))
//修改title
// let alertTitle = NSMutableAttributedString(string: string, attributes: [NSAttributedString.Key.foregroundColor : UIColor.hexColorWithAlpha(hexString: "#424242") ,NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14)])
//let attributedText = NSAttributedString.create(string, textTaps: Array(linkDic.keys))
let alertView = UIAlertController(title: title, message: nil, preferredStyle: .alert)
let confirm = UIAlertAction(title: "同意", style: .default) { action in
//
DDLog(action.title)
}
let cancel = UIAlertAction(title: "暂时不用", style: .destructive) { _ in
//
}
alertView.setValue(attributeString, forKey: kAlertMessage)
alertView.addAction(cancel)
alertView.addAction(confirm)
UIApplication.shared.windows.first?.rootViewController?.present(alertView, animated: true, completion: {
//
})
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)