效果:

 
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

Swift简单实现一个常规条款、免责声明文字+带有链接的展示形式的更多相关文章

  1. Swift - 简单封装一个工具类模板

    创建模板类(封装一个类) 例1:新建一个名字叫做 Product 的类 Product.swift File 的内容 class Product { var name: String var desc ...

  2. App免责声明

    一切移动客户端用户在下载并浏览xxxAPP软件时均被视为已经仔细阅读本条款并完全同意.凡以任何方式使用本APP,或直接.间接使用本APP资料者,均被视为自愿接受本网页相关声明和用户服务协议的约束. x ...

  3. 来自苹果的编程语言——Swift简单介绍

    关于 这篇文章简要介绍了苹果于WWDC 2014公布的编程语言--Swift. 原文作者: Lucida Blog 新浪微博 豆瓣 转载前请保留出处链接.谢谢. 前言 在这里我觉得有必要提一下Brec ...

  4. Swift 简单介绍 - 苹果最新的编程语言

    Swift 真的能够说是最新的编程语言了,2014wwdc刚刚公布,以下来了解一下都有哪些特点. 首先感谢原作者,主要内容是借鉴他的,參考链接 http://zh.lucida.me/blog/an- ...

  5. 来自苹果的编程语言——Swift简单介绍【整理】

    2014年06月03日凌晨,Apple刚刚公布了Swift编程语言,本文从其公布的书籍<The Swift Programming Language>中摘录和提取而成.希望对各位的iOS& ...

  6. 使用.NET简单实现一个Redis的高性能克隆版(三)

    译者注 该原文是Ayende Rahien大佬业余自己在使用C# 和 .NET构建一个简单.高性能兼容Redis协议的数据库的经历. 首先这个"Redis"是非常简单的实现,但是他 ...

  7. 最简单的一个Oracle定时任务

    最简单的一个Oracle定时任务一.在PLSQL中创建表:create table HWQY.TEST(CARNO     VARCHAR2(30),CARINFOID NUMBER) 二.在PLSQ ...

  8. Swift 简单的通讯录

    Swift 通讯录实战 1.功能需求 整个项目由三个界面构成:首页面(全部联系人),添加联系人界面和联系人详情界面 整个项目使用纯代码编程 数据处理方面使用一个工具类,处理所有数据的增删改查. 首页由 ...

  9. 在浏览器中简单输入一个网址,解密其后发生的一切(http请求的详细过程)

    在浏览器中简单输入一个网址,解密其后发生的一切(http请求的详细过程) 原文链接:http://www.360doc.com/content/14/1117/10/16948208_42571794 ...

随机推荐

  1. CH6802 車的放置

    原题链接 和棋盘覆盖(题解)差不多. 将行和列看成\(n+m\)个节点,且分属两个集合,如果某个节点没有被禁止,则行坐标对应节点向列坐标对应节点连边,然后就是求二分图最大匹配了. #include&l ...

  2. virualbox问题

    出不来64位虚拟系统 bios设置虚拟化可用 2.创建虚拟机 启动不了 提示 不能打开一个... 安装exten 扩张包 3.设备 -- 安装增强功能... 分辨率  设置成功

  3. Java中终止线程的三种方法

    终止线程一般建议采用的方法是让线程自行结束,进入Dead(死亡)状态,就是执行完run()方法.即如果想要停止一个线程的执行,就要提供某种方式让线程能够自动结束run()方法的执行.比如设置一个标志来 ...

  4. How to execute sudo command in remote host via SSH

    Question: I have an interactive shell script, that at one place needs to ssh to another machine (Ubu ...

  5. Two Sum IV - Input is a BST LT653

    Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...

  6. Two Sum III - Data structure design LT170

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  7. Mysql遇到的坑

    2018-04-09 这个虽然跟粗心有关,但是Mysql没报错是哪般? select sum(play_count) from tb_user_login where user_id = 61 and ...

  8. IOS初级:app的图标

    1,首先准备6张png图,分辨率一定要正确,不然报错(The app icon set named "AppIcon" did not have any applicable co ...

  9. 使用Python完成表格自动输入

    看了看<Python编程快速上手>,写了个小脚本完成12306登录数据的自动输入.如下: 1 import webbrowser 2 import pyautogui 3 import t ...

  10. Bing Developer Assistant开发随记

    Thumb很适合用来做拖动效果的,不会让鼠标轻易跑掉. Combo中的选项是当字符串输入并激发事件后自动加入的,可使用IVsUIShell.SetMRUComboText(GuidList.guidO ...