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. OpenDaylight虚拟租户网络(VTN)详解及开发环境搭建

    一.VTN简介及架构分析:   具体详见开发人员指南wiki:https://wiki.opendaylight.org/view/Release/Lithium/VTN/developer_Guid ...

  2. springboot-12-自定义拦截器的配置interceptor

    springmvc中拦截器的概念已经被弱化了, springboot中使用的也不甚广泛, 通常在用户登录等方面仍有用处 创建拦截器步骤: , 创建拦截器类继承HandlerInterceptor , ...

  3. 亿级别记录的mongodb批量导入Es的java代码完整实现

    针对mongodb亿级别或者十亿级别的模糊查询,效率不高,解决方式是使用Es查询,这样就需要把数据导入的ES中 完整的代码实现如下所示:(仅供参考) import java.io.IOExceptio ...

  4. 测试使用highlight.js的代码效果

    ---恢复内容开始--- C#代码 private void NextDateUpdate(DateTime dtt) { dtt.AddDays(); Response.Write("dt ...

  5. 我在项目中运用 IOC(依赖注入)--入门篇

    之前就听同事说过依赖注入(dependency injection).控制反转(Inversion of Control).起初听的是一头雾水,试着在项目中运用了几次,总算明白了一些,抛砖引玉,与大家 ...

  6. JVM进程状态监控

    前言 ========== 为什么需要做服务器jvm自动发现的监控呢?这个事情主要有两点原因: 1.zabbix默认监控jvm状态是使用jmx中转进行监控的,监控效率比较低下 2.zabbix使用jm ...

  7. ActiveMQ 报错 Temporary Store limit is 51200 mb

    ERROR | Temporary Store limit is 51200 mb, whilst the temporary data directory: D:\tool\apache-actil ...

  8. MySQL中文编码设置为utf-8

    MySQL中文编码设置为utf-8 原文地址:http://blog.csdn.net/wangnan537/article/details/47819167 1. 查看MySQL数据库的默认编码有如 ...

  9. 浅谈一致性哈希(My转)

    一致性哈希(Consistent hashing)算法是由 MIT 的Karger 等人与1997年在一篇学术论文(<Consistent hashing and random trees: d ...

  10. 连接数据库 JDBC、DBCP、JNDI

    一.JDBC package com.direct.util; import java.sql.Connection; import java.sql.DriverManager; import ja ...