效果:

 
IMG_F08DABE063A6-1.jpeg
class DisclamerView: UIView {
//@objc weak var vc:UIViewController?
//自定义协议
@IBInspectable var diy_protocol:String = "diyprotocol"
//超链接地址
@IBInspectable var disclamerURLStr:String = " "
//条款、免责声明描述文字
@IBInspectable var infoStr = str_disclaimer
//链接地址描述
@IBInspectable var linkStr = ""
//展示文字的大小(用于判断展示区域大小)
@IBInspectable var font = UIFont.systemFont(ofSize: 13) lazy var infoTextView:UITextView = {
let tv = UITextView()
tv.delegate = self
tv.isEditable = false
tv.backgroundColor = UIColor.clear
tv.isScrollEnabled = false
//设置页边距上边距10,左右边距各10,底边距0 上,右,下,左
tv.textContainerInset = UIEdgeInsetsMake(10, 0, 0, -5);
self.addSubview(tv)
return tv
}() override func awakeFromNib() {
super.awakeFromNib()
self.backgroundColor = UIColor.groupTableViewBackground
} override func draw(_ rect: CGRect) {
// Drawing code
let attri = NSMutableAttributedString(attributedString: NSAttributedString(string: infoStr + linkStr,
attributes:[NSAttributedStringKey.foregroundColor : UIColor.darkGray,
NSAttributedStringKey.font : font]))
if linkStr != ""{
attri.addAttributes([NSAttributedStringKey.link:(diy_protocol+"://")],
range: ((attri.string) as NSString).range(of: linkStr))
}
infoTextView.attributedText = attri
//左右两天预留5个像素
infoTextView.frame = CGRect(x: 5, y: 0, width: rect.width - 5*2, height: rect.height)
}
} extension DisclamerView:UITextViewDelegate{
//textView里带有超链接的监听代理
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
//判断超链接协议
if let sch = URL.scheme,sch == diy_protocol {
//let ndvc = SFNewsDetailVC(nibName: "SFNewsDetailVC", bundle: nil)
// ndvc.requstURL = disclamerURLStr;
//if let vc = vc as? UINavigationController{
// vc.pushViewController(ndvc, animated: true)
// }else{
// ndvc.isPresent = true
// vc?.present(ndvc, animated: true, completion: nil)
/// }
return true
}
return false
}
}

XIB使用:

self.disclamerView.linkStr = @"点击查看详情";
// CGFloat dh = [STools getDisclaimerStrContentHeightWithDSize:CGSizeMake(SWIDTH - 5*2, 10000) dFont:self.disclamerView.font] + 18;
self.h_disclamerView.constant = dh;
 
image.png
 
image.png

纯代码使用

    lazy var disclamerView:DisclamerView = {
let dv = DisclamerView()
dv.backgroundColor = color_background
let dh = STools.getDisclaimerStrContentHeight(dFont: dv.font) + 18
dv.frame = CGRect(x: 0, y: 0,width: swidth, height: dh)
dv.vc = self
return dv
}() self.tableView.tableFooterView = disclamerView

最新文章

  1. vim 常用命令逐渐熟悉以及常用的配置记录
  2. CentOS7 NTP 安装配置
  3. (转)AppiumLibrary基本操作
  4. SQL Server 2008 R2 下移动数据库的存储位置
  5. Leetcode 368. Largest Divisible Subset
  6. Effective C++ 之 Item 5:了解C++默默编写并调用哪些函数
  7. swiper中提供的动画效果
  8. jQuery的XX如何实现?——2.show与链式调用
  9. 华为OJ:火车进站
  10. applicationContext.xml存放的位置
  11. centos7.2部署最新ELK 5.3
  12. 反击黑客之对网站攻击者的IP追踪
  13. Win10 取消桌面快捷键图标
  14. linux改变apt-get安装源
  15. WordPress无法发送电子邮件,可能原因:您的主机禁用了mail()函数解决方案
  16. FTP如何通过Windows防火墙
  17. Linux必会必知
  18. solidity错误处理
  19. c 结构体中的变长数组
  20. 在ubuntu下 使用Jetty 和 Maven 开发 HelloWorld

热门文章

  1. javascript 高级程序设计 六
  2. SNP命名
  3. POJ3678 Katu Puzzle
  4. mysql5.6改进子查询实测试
  5. Python3字符编码
  6. Eclipse的下载及安装
  7. TP QQ 微信 微博登录
  8. android udp 无法收到数据 (模拟器中)
  9. .NET发送邮件的方法
  10. Git工具和GitHub的使用