Giter Site home page Giter Site logo

lyb5834 / ybattributetexttapforswfit Goto Github PK

View Code? Open in Web Editor NEW
50.0 2.0 15.0 52 KB

一行代码添加文本点击事件(swfit4.2版本)/a fast way to implement click event text(for swfit4.2)

License: MIT License

Swift 100.00%
text label attribute swift swift4-2

ybattributetexttapforswfit's Introduction

YBAttributeTextTapForSwfit

一行代码添加文本点击事件(swfit3.0版本)/a fast way to implement click event text(for swfit3.0)

效果图

(演示效果)

Objective-C版本

https://github.com/lyb5834/YBAttributeTextTapAction.git

已适配swfit4.2

#使用方法

  • 设置 label.attributedText = ?????
  • label.yb_addAttributeTapAction(["xx","xx"...]) { (string, range, int) in coding more... }
  • PS:数组里输入的要点击的字符可以重复

#重要提醒

  • 使用本框架时,最好设置一下NSParagraphStyle中lineSpacing属性,也就是行间距,如果不设置,则默认为0!
  • 使用本框架时,一定要设置label.attributedText = ????? ,不设置则无效果!!
  • 默认添加点击效果,关闭只需设置label.enabledTapEffect = false即可

#版本支持

  • xcode7.0+

  • 如果您在使用本库的过程中发现任何bug或者有更好建议,欢迎联系本人email [email protected]

ybattributetexttapforswfit's People

Contributors

lyb5834 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ybattributetexttapforswfit's Issues

swift4中有一个地方报错, 在存储属性那里用全局变量是有问题的.

  1. swift4中只需改这个地方就可以兼容.
func nsRange(from range: Range<String.Index>) -> NSRange {
//        let from = range.lowerBound.samePosition(in: utf16)
//        let to = range.upperBound.samePosition(in: utf16)
        // utf16.distance(from: utf16.startIndex, to: from)  //utf16.distance(from: from, to: to)
        return NSRange.init(range, in: self)
//        return NSRange(location:self.startIndex ,length: )
    }

注释的地方是您的代码。

2、在extension中添加储存属性可以使用runtime

private func setIsTapAction(isTapAction: Bool) {
        objc_setAssociatedObject(self, &AssociatedKeys.tapAction, isTapAction as Bool, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
    }
    
    private func getIsTapAction() -> Bool {
        let isTap = objc_getAssociatedObject(self, &AssociatedKeys.tapAction) as? Bool
        return isTap != nil ? isTap! : true
    }

如果用原来的实现方式会出现第二地方添加的action会清空上一次的添加的.

Swift 版本问题

Swift 版有问题呢,除了一些强解包,整体逻辑也有些问题,作者最好在 ReadMe 中建议下使用 OC 版本。
最后十分感谢~

关于hitTest

override open func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {

这个方法一直在调用,而且isTapAction这个属性一旦置为true 就不会再置为false了,
我出现了了几次问题,在tableveiw中使用这个,会闪退

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.