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的更多相关文章

  1. Swift版iOS游戏框架Sprite Kit基础教程下册

    Swift版iOS游戏框架Sprite Kit基础教程下册 试读下载地址:http://pan.baidu.com/s/1qWBdV0C 介绍:本教程是国内唯一的Swift版的Spritekit教程. ...

  2. Swift版音乐播放器(简化版),swift音乐播放器

    这几天闲着也是闲着,学习一下Swift的,于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神, 希望对大家有帮助! 这个DEMO里,使用到了 AudioPlayer(对音 ...

  3. 快速排序OC、Swift版源码

    前言: 你要问我学学算法在工作当中有什么用,说实话,当达不到那个地步的时候,可能我们不能直接的感觉到它的用处!你就抱着这样一个心态,当一些APP中涉及到算法的时候我不想给其他人画界面!公司的项目也是暂 ...

  4. iOS可视化动态绘制八种排序过程(Swift版)

    前面几篇博客都是关于排序的,在之前陆陆续续发布的博客中,我们先后介绍了冒泡排序.选择排序.插入排序.希尔排序.堆排序.归并排序以及快速排序.俗话说的好,做事儿要善始善终,本篇博客就算是对之前那几篇博客 ...

  5. swift版的CircleView

    swift版的CircleView 效果图 源码 // // CircleView.swift // CircleView // // Created by YouXianMing on 15/10/ ...

  6. swift版的GCD封装

    swift版的GCD封装 说明 本人针对swift封装了GCD,包括GCDQueue,GCDGroup,GCDTimer以及GCDSemaphore,使用较为便利. 源码 https://github ...

  7. swift版的元组

    swift版的元组 说明 元组的内容并不多,使用的话跟普通变量类似,以下是测试源码: // // ViewController.swift // Tuples // // Created by You ...

  8. swift版的枚举变量

    swift版的枚举变量 swift的枚举类型跟普通的类是极为类似的,使用的时候,请不要以为他是一个常量,以下是测试用源码 // // ViewController.swift // SwiftEnum ...

  9. 关东升的iOS实战系列图书 《iOS实战:入门与提高卷(Swift版)》已经上市

             承蒙广大读者的厚爱我的 <iOS实战:入门与提高卷(Swift版)>京东上市了,欢迎广大读者提出宝贵意见.http://item.jd.com/11766718.html ...

随机推荐

  1. 12-mapReduce的简介和yarn搭建

    Hadoop的核心组件之er: mapreduce 目前的计算框架 mapreduce spark storm flink(阿里) mapreduce的核心理念: 移动计算, 而不是移动数据(redu ...

  2. vue 监听对象里的特定数据

    vue  监听对象里的特定数据变化 通常是这样写的,只能监听某一个特定数据 watch: { params: function(val) { console.log(val) this.$ajax.g ...

  3. 基于obs+nginx-rtmp-module搭建自己直播的系统

    前言 一句唠叨,工欲善其事,必先利其器,在程序员的工作里,搭建各种环境往往花费过多不必要的时间,这里建议搭建服务端环境时,尽量避开win.macos这种系统,个人比较推崇centos. 操作 下面以c ...

  4. 安装和使用mongodb

    环境: Ubuntu 13.04 安装MongoDB $sudo apt-get install mongodb 会自动安装libpcrecpp0 libboost-system1.42.0 libb ...

  5. JS事件细分

    鼠标相关事件执行顺序 与 onmousedown 事件相关连得事件发生次序( 鼠标左侧/中间 按钮): onmousedown onmouseup onclick 与 onmousedown 事件相关 ...

  6. Linux系统资源管理 之 硬件信息

    1. CPU lscpu : 一般不加参数,直接使用该命令. cat /proc/cpuinfo: 该文件中列出了CPU的详细信息,类似于'lscpu'命令 lscpu [niesh @niesh D ...

  7. Android 操作Sqlite

    首先要用一个类来继承SQLiteOpenHelper,并必须实现 public DatabaseHelper(Context context, String name, CursorFactory f ...

  8. BASE64转文件下载

    你可以用HTML 5 注意:返回的文件数据必须是base 64编码的,因为您不能对二进制数据进行JSON编码 在我的AJAX我得到了如下的数据结构: <!DOCTYPE html> < ...

  9. Node.js Express 框架2

    文件上传 以下我们创建一个用于上传文件的表单,使用 POST 方法,表单 enctype 属性设置为 multipart/form-data. index.html <html> < ...

  10. 常用js-API

    jquery.base64.js //下面是64个基本的编码 var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm ...