Highlighter will magically find UI objects such as UILabel, UITextView, UITexTfield, UIButton

Overview

Highlighter

Awesome Version Carthage Compatible License: MIT Build Status Platform Swift 5.0

Updates

See CHANGELOG for details

Intoduction

πŸ– Highlight whatever you want! Highlighter will magically find UI objects such as UILabel, UITextView, UITexTfield, UIButton in your UITableViewCell or other Class.

See YNSearch for advanced usage

demo

Requirements

Highlighter is written in Swift 5.0. Compatible with iOS 9.0+

Installation

Cocoapods

Highlighter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Highlighter'

Carthage

github "younatics/Highlighter"

Usage

You can search any UIView using view.highlight(text:normal:highlight:type:) It will search subviews for the provided text and highlight them using the attributes provided.

To search all supported subview use:

view.highlight(text: "Foo", normal: normalAttributes, highlight: highlightedAttributes)

or you can limit the search to a single type using:

view.highlight(text: "Foo", normal: normalAttributes, highlight: highlightedAttributes, type: UIButton.self)

Examples

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = self.ynSearchListViewDelegate?.ynSearchListView(tableView, cellForRowAt: indexPath) as? SearchViewCell else { return UITableViewCell() }
            
  if let changedText = ynSearchTextFieldText {
    cell.highlight(text: changedText, normal: nil, highlight: [NSBackgroundColorAttributeName: UIColor.yellow])
    }
  return cell
  }
}

References

Please tell me or make pull request if you use this library in your application :)

MotionBook

YNSearch

Author

younatics Twitter

License

Highlighter is available under the MIT license. See the LICENSE file for more info.

Comments
  • Pop implementation

    Pop implementation

    As discussed in https://github.com/younatics/Highlighter/issues/2 here is the POP implementation.

    This should be a major version change since it contains breaking changes to the syntax.

    Please give it a quick test before merging.

    🀘

    opened by IanKeen 2
  • POP Implementation

    POP Implementation

    Hey, Interesting lib

    I had a quick play at a protocol oriented version if you are interested

    https://gist.github.com/IanKeen/537d70bf02fad763c096e6fbb5c1dc69

    The biggest pro to this approach is you are able to break out the highlightable elements and use protocol extensions to provide a default highlighting implementation.

    The boilerplate for the elements that conform to Highlightable would have been reduced greatly if UITextView didn't use IUOs for its text/attributedText properties :(

    The only API change this introduces is the removal of the HighlighterType enum. Instead you just pass in the type of the item you are targeting i.e. UIButton.self for buttons or nil for everything.

    Let me know if you'd be interested in a PR

    opened by IanKeen 1
  • Out of bounds, case crash.

    Out of bounds, case crash.

    Problem

    App crashed when the text of UILabel is come from network data parse.May be caused by string encoding. I simulated the scene with SwiftPlayground.

    let key = "倩"
    let text = String(data: "ζ˜Žε€©εΌ€ε§‹".data(using: .unicode)!, encoding: .unicode)!
    let ranges = text.lowercased().ranges(of: key)
    print("matchedRanges: \(ranges)")
    // matchedRanges: [Range(Swift.String.Index(_rawBits: 196608)..<Swift.String.Index(_rawBits: 393216))]
    
    print("originText.endIndex: \(text.endIndex)")
    // originText.endIndex: Index(_rawBits: 262144)
    
    print("lowercased.endIndex: \(text.lowercased().endIndex)")
    // lowercased.endIndex: Index(_rawBits: 786432)
    

    The upperBound of matched range is greater than the originText.endIndex.

    Solution

    Remove the lowercased option before match range and use CompareOptions.caseInsensitive as the default value of ranges method.

    I am happy to submit PR if you allow it.

    opened by orangeince 0
  • NSAttributedString extension highlight function bug.

    NSAttributedString extension highlight function bug.

    There is a bug in the highlight function. It occurs when more than one range is in the input. Line 22: highlightString.append(self.containAttribute(originText: originText, bound: ranges[i], attributes: highlightAttributes))

    It takes wrong occurrence. Next, instead of needed one. For example if originText = "String string String" and searchText = "string", then result will be (omitting attributes) "string String String". In fact you can clearly see this bug in the introduction gif (https://raw.githubusercontent.com/younatics/Highlighter/master/Images/Highlighter.gif)

    opened by mgorvat 0
  • add unHighlight even for attribute text

    add unHighlight even for attribute text

    When the project use Highlighter to highlight cell, if the cell contain label using attribute string. This highlight method will make the label cache highlighted attribute string

    opened by ducnguyenenterprise 0
Releases(1.4.0)
Owner
Kyle Yi
Kyle Yi
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.

Link Previewer for iOS, macOS, watchOS and tvOS It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.

Leonardo Cardoso 1.3k Jan 2, 2023
Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm

Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm. Creating a chan

Christoffer Winterkvist 127 Jun 3, 2022
Type-Safe Associated Objects in Swift

Type-Safe Associated Objects in Swift TSAO is an implementation of type-safe associated objects in Swift. Objective-C associated objects are useful, b

Lily Ballard 135 Dec 21, 2022
Observe objects in SwiftUI Views which may be nil

ObservedOptionalObject Rationale SwiftUIs @ObservedObject requires that the observed object actually exists. In some cases it's convenient to observe

Matthias Bartelmeß 7 Jul 20, 2022
Getting square objects down round holes

Enough with the bazillion lines of array parsing logic. YOLO. @import YOLOKit; campaigns.reject(^(PPCampaign *campaign){ return campaign.locked;

Max Howell 662 Nov 20, 2022
A Swift collection of unique, ordered objects

Introduction OrderedSet is essentially the Swift equivalent of Foundation's NSOrderedSet/NSMutableOrderedSet. It was created so Swift would have a uni

Weebly 248 Sep 14, 2022
Validate iOS, Android, and Mac localizations. Find errors in .strings, .stringsdict, and strings.xml files.

Locheck An Xcode and Android localization file validator. Make sure your .strings, .stringsdict, and strings.xml files do not have any errors! What do

Asana 73 Dec 13, 2022
High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

Haoking 336 Nov 26, 2022
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

IQKeyboardManager While developing iOS apps, we often run into issues where the iPhone keyboard slides up and covers the UITextField/UITextView. IQKey

Mohd Iftekhar Qurashi 15.9k Jan 8, 2023
This project will add a done button on your UITextField and UITextView

This project will add a done button on your UITextField and UITextView

Botla Venkatesh 0 Nov 23, 2021
UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.

Deprecated Please use JVFloatLabeledTextField instead or feel free to chime in on an issue if you'd like to take over the repo. RPFloatingPlaceholders

rob phillips 1.1k Jan 5, 2023
Animated UITextField and UITextView replacement for iOS

AnimatedTextInput iOS custom text input component used in the Jobandtalent app. Installation Use cocoapods to install this custom control in your proj

jobandtalent 757 Dec 15, 2022
Prevent keyboard from covering UITextField/UITextView, includes Swift and Objective-C APIs

Prevent keyboard from covering UITextField/UITextView with only one line of code, includes Swift and Objective-C APIs.

LiuChang 8 Oct 24, 2022
Markdown syntax highlighter for iOS

Marklight Markdown syntax highlighter for iOS and macOS. Description Marklight is a drop in component to easily add realtime Markdown syntax highlight

Matteo Gavagnin 539 Dec 29, 2022
iOS & OSX Syntax Highlighter.

Highlightr Highlightr is an iOS & macOS syntax highlighter built with Swift. It uses highlight.js as it core, supports 185 languages and comes with 89

J.P. Illanes 1.4k Dec 23, 2022
Multiple state tap-to-toggle UIButton (like old camera flash button)

Multiple State Toggle UIButton A UIButton subclass that implements tap-to-toggle button text. (Like the camera flash and timer buttons) Usage Just cre

Yonat Sharon 83 Oct 11, 2022
πŸ”₯ PMSuperButton is a powerful UIButton coming from the countryside, but with super powers! 😎

PMSuperButton is a powerful UIButton coming from the countryside, but with super powers! ?? An easy way to create custom and complex buttons with cust

Paolo Musolino 720 Nov 17, 2022