All Projects → rinov → Regeributedtextview

rinov / Regeributedtextview

Licence: mit
RegeributedTextView is a subclass of UITextView that supports fully attribute string based on regular expression.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Regeributedtextview

Uitextfield Navigation
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews
Stars: ✭ 436 (+990%)
Mutual labels:  xcode, uitextview
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (+640%)
Mutual labels:  xcode, uitextview
Swiftlyext
SwiftlyExt is a collection of useful extensions for Swift 3 standard classes and types 🚀
Stars: ✭ 31 (-22.5%)
Mutual labels:  xcode
Sqlitelib
Easily build a custom SQLite static library for use in macOS and iOS frameworks and apps.
Stars: ✭ 38 (-5%)
Mutual labels:  xcode
Rainbowbar
Progress bar with wild animation for notched status bar
Stars: ✭ 34 (-15%)
Mutual labels:  xcode
Metro Lights
A dark Xcode theme inspired by City Lights for Atom.
Stars: ✭ 32 (-20%)
Mutual labels:  xcode
Sitrep
A source code analyzer for Swift projects.
Stars: ✭ 984 (+2360%)
Mutual labels:  xcode
Hmlldb
HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps.
Stars: ✭ 30 (-25%)
Mutual labels:  xcode
Inputaccessoryview
Input Accessory View for Commenting and Chat User Interfaces built in Swift, if you like it please "☆"
Stars: ✭ 39 (-2.5%)
Mutual labels:  uitextview
Viper Templates
Swift Xcode templates for creating VIPER architecture stacks
Stars: ✭ 33 (-17.5%)
Mutual labels:  xcode
Swiftuiwindowstyles
Showcase of window and toolbar style combinations possible with SwiftUI on macOS.
Stars: ✭ 38 (-5%)
Mutual labels:  xcode
Sm9 free
基于Miracl的国密算法SM9实现
Stars: ✭ 33 (-17.5%)
Mutual labels:  xcode
React Native Video Processing
Native Video editing/trimming/compressing 🎥 library for React-Native
Stars: ✭ 959 (+2297.5%)
Mutual labels:  xcode
Tangramkit
TangramKit is a powerful iOS UI framework implemented by Swift. It integrates the functions with Android layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,LayoutSizeClass to build your App 自动布局 UIView UITableView UICollectionView
Stars: ✭ 984 (+2360%)
Mutual labels:  xcode
Mod Pbxproj
A python module to manipulate XCode projects
Stars: ✭ 959 (+2297.5%)
Mutual labels:  xcode
Cobalt2 Vim Theme
Vim port of cobalt2 sublime theme
Stars: ✭ 38 (-5%)
Mutual labels:  xcode
Instories
iOS app for viewing Instagram stories anonymously.
Stars: ✭ 31 (-22.5%)
Mutual labels:  xcode
Isimulator
iSimulator is a GUI utility to control the Simulator, and manage the app installed on the simulator.
Stars: ✭ 963 (+2307.5%)
Mutual labels:  xcode
Onehalf
Clean, vibrant and pleasing color schemes for Vim, Sublime Text, iTerm, gnome-terminal and more.
Stars: ✭ 974 (+2335%)
Mutual labels:  xcode
Lldebugtoolswift
LLDebugTool is a debugging tool for developers and testers that can help you analyze and manipulate data in non-xcode situations.
Stars: ✭ 40 (+0%)
Mutual labels:  xcode

RegeributedTextView

Build Status codecov Cocoapods Carthage License Platform [Language

RegeributedTextView is a subclass of UITextView that supports fully attribute string based on regular expression.

DEMO

Usage

import RegeributedTextView

and you can use RegeributedTextView as subclass of UITextView in Interface Builder.

InterfaceBuilder

It is simple to use an attribute string.

Chage the text color:

textView.addAttribute(.all, attribute: .textColor(.red)))

Instead of .all, you can use regular expression .

textView.addAttribute(".*", attribute: .textColor(.red)))

If you want highlight a mention and hash tag like a SNS, you can use following parameters.

textView.addAttribute(.mention, attribute: .bold))
textView.addAttribute(.hashTag, attribute: .textColor(.blue)))

Available attribute type

Attribute Type
backgroundColor UIColor
bold -
boldWithFontSize CGFloat
font UIFont
fontName String
fontSize CGFloat
italic CGFloat
linkColor UIColor
shadow Shadow
strikeColor UIColor
strikeWithThickness CGFloat
strokeWidth CGFloat
textColor UIColor
underline UnderlineStyle
underlineColor UIColor

Link text behavior

In swift 4, The property linkTextAttributes of UITextView can designate the link text behavior but it is not possible to coloring a few text separately in the same text. In this case, you can use attributes text based on regular expression like this.

e.g. Set text color separately.

textView.addAttribute("@[a-zA-Z0-9]+", attributes: [.textColor(.black), .bold], values: ["Type": "Mention"])
textView.addAttribute("#[a-zA-Z0-9]+", attribute: .textColor(.blue), values: ["Type": "HashTag"])

In RegeributedTextView, All attributed text can be detected for each word by tapping. and you can detect a tap event of link text by RegeributedTextViewDelegate. The arguments of values can embbed any values.

func regeributedTextView(_ textView: RegeributedTextView, didSelect text: String, values: [String : Any]) {
    print("Selected word: \(text)")
    if let url = values["Type"] as? String {
        // Do something
    }

Advanced settings

public func addAttribute(_ regexString: String, attribute: TextAttribute, values: [String: Any] = [:], priority: Priority = .medium, applyingIndex: ApplyingIndex = .all)

To control an attribute text, you can use Prioriry and ApplyingIndex. Priority represents that attribute string priority. Attribute text range is sometime overlaped, so this property enable to control attribute string priority like AutoLayout.

Rules:

  • The new attribute priority is greater than the current attribute, it's overwriten.
  • The new attribute priority is less than the current attribute, it's ignored.

Applying Index represents which text should be applied an attribute because it is difficult to control the attribute text order using only regular expression.

e.g. Applying only first element

let userName = "rinov"
textView.addAttribute(userName, attribute: .bold, applyingIndex: .first)

ApplyingIndex is available following patterns.

ApplyingIndex Description
all All matched text is applyed
first Only first element is applyed
firstFrom(Int) It's applyed for specified number of times from the start index of the text
ignoreFirstFrom(Int) It's ignore for specified number of times from the start index of the text
last Only last element is applyed
lastFrom(Int) It's applyed for specified number of times from the end index of the text
ignoreLastFrom(Int) It's ignore for specified number of times from the end index of the text
indexOf(Int) Applyed only specified index
ignoreIndexOf(Int) Ignore only specified index

Requirements

Swift 4

XCode 9

Installation

Cocoapods:

$: pod repo update

pod "RegeributedTextView"
  • Swift3.x: pod "RegeributedTextView" , '~> 0.1.1'

  • Swift4.x: pod "RegeributedTextView" , '~> 0.2.1'

and

$: pod install

or

Carthage:

github "rinov/RegeributedTextView"

and

$: carthage update --platform iOS

Author

rinov, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].