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. Python虚拟环境中pip install时没有权限问题

    virtualenv Permission denied 新建的python虚拟环境的目录的所属者必须是当前用户,才不会出现这种错误 比如 virtualenv py27 sudo chown zzf ...

  2. openTSDB(转)

    1.OpenTSDB介绍 1.1.OpenTSDB是什么?主要用途是什么? 官方文档这样描述:OpenTSDB is a distributed, scalable Time Series Datab ...

  3. MongoDB之数据库管理

    前面补充过把MongoDB作为服务,今天主要了解数据库管理,在操作之前先把MongoDB服务打开. 一.显示数据库清单 如果想查看数据库列表可以使用show dbs. 二.切换数据库 通过使用Mong ...

  4. C#.NET下转换泛型列表为JSON格式

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Te ...

  5. IOS第三方之SVProgressHUD

    这个第三方和MBProgressHUD差不多,也挺简单的. // // ViewController.m // ProgressHUD // // Created by City--Online on ...

  6. 问题集录--Java高级软件工程师面试考纲(转)

    如果要应聘高级开发工程师职务,仅仅懂得Java的基础知识是远远不够的,还必须懂得常用数据结构.算法.网络.操作系统等知识.因此本文不会讲解具体的技术,笔者综合自己应聘各大公司的经历,整理了一份大公司对 ...

  7. rabbitmq-channel方法介绍

    先介绍rabbmitmq的几个方法: // 声明一个队列 -// queue 队列名称 // durable 为true时server重启队列不会消失 (是否持久化) // exclusive 队列是 ...

  8. javascript正则表达式获取控制

    正则表达式的元字符是包含特殊含义的字符,他们有一些特殊的功能,可以控制匹配模式的方式,反斜杠后的元字符将失去其特殊含义 单个字符 元字符 匹配情况 . 匹配除换行符外的任意字符 [a-z0-9] 匹配 ...

  9. MyBatis --- 配置步骤

    本文并非具体的细节,而是主要的配置步骤 概述 MyBatis 是半自动的ORM 框架,在MyBatis 整合 Spring Boot 的时候步骤比较繁琐,所以写下此篇纪录一下步骤. 使用 MyBati ...

  10. 通过微信分享链接,后面被加上from=singlemessage&isappinstalled=1导致网页打不开

    微信分享会根据分享的不同,为原始链接拼接如下参数: 朋友圈   from=timeline&isappinstalled=0微信群   from=groupmessage&isappi ...