Skip to content

Instantly share code, notes, and snippets.

@jjaffeux
Forked from michael-erasmus/Gemfile
Created September 30, 2012 21:50
Show Gist options
  • Save jjaffeux/3808548 to your computer and use it in GitHub Desktop.
Save jjaffeux/3808548 to your computer and use it in GitHub Desktop.
ttt_attributed_label example
class ExampleViewController < UIViewController
def viewDidLoad
view.backgroundColor = :white.uicolor
frame = [[85, 200], [150, 20]]
lbl = TTTAttributedLabel.alloc.initWithFrame(frame).tap do |l|
l.backgroundColor = :clear.uicolor
l.textAlignment = UITextAlignmentRight
add_text(l)
end
view << lbl
end
def add_text(label)
text = "blue red and green"
label.setText(text, afterInheritingLabelAttributesAndConfiguringWithBlock: -> mutable{
[:blue, :red, :green].each do |color|
range = mutable.string.rangeOfString(color.to_s, options:NSCaseInsensitiveSearch)
mutable.addAttribute KCTForegroundColorAttributeName, value:color.uicolor.CGColor, range:range
end
mutable
})
label
end
end
source "https://rubygems.org"
gem 'sugarcube'
gem 'motion-cocoapods', :git => 'https://github.com/HipByte/motion-cocoapods.git' # 1.1.4 seems broken
Motion::Project::App.setup do |app|
...
app.frameworks += ['CoreText']
app.pods do
pod 'TTTAttributedLabel'
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment