swift版的StringAttribute
swift版的StringAttribute
效果
源码
https://github.com/YouXianMing/Swift-StringAttribute
//
// StringAttributeProtocol.swift
// Swift-StringAttribute
//
// Created by YouXianMing on 15/10/8.
// Copyright © 2015年 YouXianMing. All rights reserved.
// import Foundation @objc protocol StringAttributeProtocol { /**
富文本属性名字 - returns: 属性名字
*/
func attributeName() -> NSString; /**
属性对应的值 - returns: 对应的值
*/
func attributeValue()-> AnyObject; /**
属性设置生效范围 - returns: 生效范围
*/
optional func effectiveStringRange() -> NSRange;
}
//
// StringAttribute.swift
// Swift-StringAttribute
//
// Created by YouXianMing on 15/10/8.
// Copyright © 2015年 YouXianMing. All rights reserved.
// import UIKit class StringAttribute: NSObject, StringAttributeProtocol { // MARK: 公用的属性 /// 富文本生效范围
var effectRange : NSRange! = NSMakeRange(, ) // MARK: 公用的方法 /**
属性有效范围 - returns: 有效范围
*/
func effectiveStringRange() -> NSRange { return effectRange
} // MARK: ==由子类重写的方法== /**
/////////////////
由子类重写
///////////////// 属性名字 - returns: 属性名字
*/
func attributeName() -> NSString { fatalError("must be overwrote by subclass")
} /**
/////////////////
由子类重写
///////////////// 属性值 - returns: 属性值
*/
func attributeValue()-> AnyObject { fatalError("must be overwrote by subclass")
}
}
//
// NSMutableAttributedString+StringAttribute.swift
// Swift-StringAttribute
//
// Created by YouXianMing on 15/10/8.
// Copyright © 2015年 YouXianMing. All rights reserved.
// import Foundation extension NSMutableAttributedString { /**
添加富文本对象 - parameter stringAttribute: 实现了StringAttributeProtocol协议的对象
*/
func addStringAttribute(stringAttribute : StringAttributeProtocol) { self.addAttribute(stringAttribute.attributeName() as String,
value: stringAttribute.attributeValue(),
range: stringAttribute.effectiveStringRange!())
} /**
消除指定的富文本对象 - parameter stringAttribute: 实现了StringAttributeProtocol协议的对象
*/
func removeStringAttribute(stringAttribute : StringAttributeProtocol) { self.removeAttribute(stringAttribute.attributeName() as String,
range: stringAttribute.effectiveStringRange!())
}
}
分析
swift版的StringAttribute的更多相关文章
- Swift版iOS游戏框架Sprite Kit基础教程下册
Swift版iOS游戏框架Sprite Kit基础教程下册 试读下载地址:http://pan.baidu.com/s/1qWBdV0C 介绍:本教程是国内唯一的Swift版的Spritekit教程. ...
- Swift版音乐播放器(简化版),swift音乐播放器
这几天闲着也是闲着,学习一下Swift的,于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神, 希望对大家有帮助! 这个DEMO里,使用到了 AudioPlayer(对音 ...
- 快速排序OC、Swift版源码
前言: 你要问我学学算法在工作当中有什么用,说实话,当达不到那个地步的时候,可能我们不能直接的感觉到它的用处!你就抱着这样一个心态,当一些APP中涉及到算法的时候我不想给其他人画界面!公司的项目也是暂 ...
- iOS可视化动态绘制八种排序过程(Swift版)
前面几篇博客都是关于排序的,在之前陆陆续续发布的博客中,我们先后介绍了冒泡排序.选择排序.插入排序.希尔排序.堆排序.归并排序以及快速排序.俗话说的好,做事儿要善始善终,本篇博客就算是对之前那几篇博客 ...
- swift版的CircleView
swift版的CircleView 效果图 源码 // // CircleView.swift // CircleView // // Created by YouXianMing on 15/10/ ...
- swift版的GCD封装
swift版的GCD封装 说明 本人针对swift封装了GCD,包括GCDQueue,GCDGroup,GCDTimer以及GCDSemaphore,使用较为便利. 源码 https://github ...
- swift版的元组
swift版的元组 说明 元组的内容并不多,使用的话跟普通变量类似,以下是测试源码: // // ViewController.swift // Tuples // // Created by You ...
- swift版的枚举变量
swift版的枚举变量 swift的枚举类型跟普通的类是极为类似的,使用的时候,请不要以为他是一个常量,以下是测试用源码 // // ViewController.swift // SwiftEnum ...
- 关东升的iOS实战系列图书 《iOS实战:入门与提高卷(Swift版)》已经上市
承蒙广大读者的厚爱我的 <iOS实战:入门与提高卷(Swift版)>京东上市了,欢迎广大读者提出宝贵意见.http://item.jd.com/11766718.html ...
随机推荐
- 解决python3与python2的pip命令冲突问题冲突(window版)
解决方法再上一篇有大概讲解: python开发环境安装配置 这里做一些补充: 上一篇说过,删除python3和python2中的python.exe文件后关闭dos窗口,重新打开dos,就可以进行安装 ...
- python:rs, ws, es = select.select(inputs, [], []) --报错error 10022
昨晚折腾的1个多钟,直到3点多才睡,感觉自己也是热爱代码了,敲3个多钟一点也不累(其实是为了凌晨6点起来抢票回家了^_^) 练习python中select进行异步通信-防止socket.recv方法阻 ...
- python3 连接HBase
db_url = 'http://47.93.89.99:8765' from traceback import format_exc import phoenixdb as pb class Uti ...
- springboot-6-整合jdbc
如果有整合jpa了, 那么在dao中直接, 不需要引入依赖 @Resource private JdbcTempalte jdbcTempalte; 如果没有的话, 就先在pom.xml中加入依赖 & ...
- WPF中List的Add()与Insert()方法的区别
先来看看定义: // Summary: // Adds an object to the end of the System.Collections.Generic.List<T>. // ...
- 使用Mac命令别名,提升工作效率
为系统添加命令别名可以提高我们的工作效率,告别命令繁琐,庸长的的烦恼. Mac的~/.bash_profile文件提供了为系统添加命令别名的地方.所以我们要操作的也是这个文件. 下面是修改~/.bas ...
- [PY3]——面向对象编程(1)
类的对象 有三种对象 可以做什么操作 包括什么属性 类对象 属性引用.实例化 函数方法.内置的属性.类变量 实例对象 属性引用 函数方法.类变量.实例变量 方法对象 1. 类对象.实例对象.方法对象 ...
- [转]Lost parameter value during SQL trace in EF Core DbParameter 为 问号 ?
本文转自:https://stackoverflow.com/questions/44202478/lost-parameter-value-during-sql-trace-in-ef-core 问 ...
- How to update Ionic cli and libraries
1)npm outdated 2)手动修改你项目的package.json文件,找对应的版本号 3)npm update 重新安装包就可以了. 转自:http://devfanaticblog.com ...
- python3.3 unicode(encode&decode)
最近在用python写多语言的一个插件时,涉及到python3.x中的unicode和编码操作,本文就是针对编码问题研究的汇总,目前已开源至github.以下内容来自项目中的README. 1 ASC ...