0.0
No commit activity in last 3 years
No release in over 3 years
Drop in replacement for UILabel with support for mentions, links and hashtags for RubyMotion
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

EnchantedQuill

EnchantedQuill is a rubymotion port of ActiveLabel.swift, just like the maintainer of that gem I had also tried different cocoapods that were drop in replacements of UILabel but they were either a bit complex to implement or just doing too much. I decided to go with ActiveLabel.swift because its API is cleaner and simpler to implement and understand.

Features

  • Support for Hashtags, Mentions, Categories and Links
  • Super easy to use and lightweight
  • Acceptable test coverage 😄

Alt Text

Installation

Add this line to your application's Gemfile:

gem 'enchanted_quill'

And then execute:

$ bundle

Usage

label                         = EnchantedQuill::Label.alloc.init
label.text                    = text
label.textColor               = UIColor.blackColor
label.font                    = UIFont.systemFontOfSize(12)
label.mention_color           = UIColor.colorWithRed(85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1)
label.mention_selected_color  = UIColor.colorWithRed(85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1).colorWithAlphaComponent(0.5)
label.hashtag_color           = UIColor.colorWithRed(238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1)
label.hashtag_selected_color  = UIColor.colorWithRed(238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1).colorWithAlphaComponent(0.5)
label.category_color          = UIColor.brownColor
label.category_selected_color = UIColor.brownColor.colorWithAlphaComponent(0.5)
label.url_color               = UIColor.colorWithRed(85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1)
label.url_selected_color      = UIColor.colorWithRed(85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1).colorWithAlphaComponent(0.5)

# Handle Paragraph Styling
label.line_spacing            = 5
label.line_height_multiple    = 1.5
label.minimum_line_height     = 20
label.maximum_line_height     = 30

label.handle_mention_tap do |mention|
  p "Mention #{mention}"
end

label.handle_category_tap do |category|
  p "Category #{category}"
end

label.handle_url_tap do |url|
  p "URL #{url.absoluteString}"
end

label.handle_hashtag_tap do |hashtag|
  p "Hashtag #{hashtag}"
end

Better Performance

For better performance use the customize block, this basically groups all customizations on the label and refreshes the textContainer once instead of refreshing each time an attribute is set.

label.customize do
  label.backgroundColor         = UIColor.blackColor
  label.text                    = text
  label.textColor               = UIColor.whiteColor
  label.font                    = UIFont.systemFontOfSize(12)
  label.numberOfLines           = 0
  label.mention_color           = UIColor.colorWithRed(85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1)
  label.mention_selected_color  = UIColor.colorWithRed(85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1).colorWithAlphaComponent(0.5)
  label.hashtag_color           = UIColor.colorWithRed(238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1)
  label.hashtag_selected_color  = UIColor.colorWithRed(238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1).colorWithAlphaComponent(0.5)
  label.category_color          = UIColor.brownColor
  label.category_selected_color = UIColor.brownColor.colorWithAlphaComponent(0.5)
  label.url_color               = UIColor.colorWithRed(85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1)
  label.url_selected_color      = UIColor.colorWithRed(85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1).colorWithAlphaComponent(0.5)

  label.handle_mention_tap do |mention|
    alert('Mention', mention)
  end

  label.handle_category_tap do |category|
    alert('Category', category)
  end

  label.handle_url_tap do |url|
    alert('URL', url.absoluteString)
  end

  label.handle_hashtag_tap do |hashtag|
    alert('HashTag', hashtag)
  end

  label.adjustsFontSizeToFitWidth = true
end

Credits

A special thanks to @optonaut for implementing such an easy to use pod for swift. 👍

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/paddingtonsbear/enchanted_quill. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.