All Projects → draveness → Typeset

draveness / Typeset

Licence: mit
Deal with AttributedString efficiently

Projects that are alternatives of or similar to Typeset

Prestyler
Elegant text formatting tool in Swift 🔥
Stars: ✭ 36 (-92.14%)
Mutual labels:  string, nsattributedstring
Attributedstring
基于Swift插值方式优雅的构建富文本, 支持点击长按事件, 支持不同类型过滤, 支持自定义视图等.
Stars: ✭ 294 (-35.81%)
Mutual labels:  string, nsattributedstring
Transformer
Easy Attributed String Creator
Stars: ✭ 278 (-39.3%)
Mutual labels:  nsattributedstring
Ustring
The Hoa\Ustring library.
Stars: ✭ 403 (-12.01%)
Mutual labels:  string
Underscore.string
String manipulation helpers for javascript
Stars: ✭ 3,355 (+632.53%)
Mutual labels:  string
Multilanguages
Android 多语种适配框架,兼容高版本,适配第三方库语种
Stars: ✭ 299 (-34.72%)
Mutual labels:  string
Competitive Programming Repository
Competitive Programming templates that I used during the past few years.
Stars: ✭ 367 (-19.87%)
Mutual labels:  string
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (-41.48%)
Mutual labels:  string
Nudein
An easy-to-use attributed text view for iOS Apps,use like masonry
Stars: ✭ 450 (-1.75%)
Mutual labels:  nsattributedstring
Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: ✭ 322 (-29.69%)
Mutual labels:  string
Commonmarkattributedstring
Create NSAttributedStrings from Markdown Text
Stars: ✭ 382 (-16.59%)
Mutual labels:  nsattributedstring
Bistring
Bidirectionally transformed strings
Stars: ✭ 326 (-28.82%)
Mutual labels:  string
Coderchef Kitchen
The official repository for our programming kitchen which consists of 50+ delicious programming recipes having all the interesting ingredients ranging from dynamic programming, graph theory, linked lists and much more. All the articles contain beautiful images and some gif/video at times to help clear important concepts.
Stars: ✭ 306 (-33.19%)
Mutual labels:  string
Sjattributesfactory
Simplify operation NSAttributedString, make writing easier. Attributes String Editing Factory. iOS 富文本编辑, 让代码更清晰. 文本编辑, 高度计算, 正则匹配等待... 简便操作, 让你爽到爆!
Stars: ✭ 372 (-18.78%)
Mutual labels:  nsattributedstring
Portable Utf8
🉑 Portable UTF-8 library - performance optimized (unicode) string functions for php.
Stars: ✭ 405 (-11.57%)
Mutual labels:  string
Cupcake
An easy way to create and layout UI components for iOS (Swift version).
Stars: ✭ 273 (-40.39%)
Mutual labels:  nsattributedstring
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (-29.91%)
Mutual labels:  string
React Element To Jsx String
Turn a ReactElement into the corresponding JSX string
Stars: ✭ 349 (-23.8%)
Mutual labels:  string
Colorful
Terminal string styling done right, in Python 🐍 🎉
Stars: ✭ 456 (-0.44%)
Mutual labels:  string
Xorstr
heavily vectorized c++17 compile time string encryption.
Stars: ✭ 435 (-5.02%)
Mutual labels:  string

Version Build Status MIT License Platform


Typeset makes it easy to create NSAttributedString

@"Hello typeset".typeset
   .match(@"Hello").fontSize(40)
   .match(@"type").purple
   .match(@"set").blue
   .string;

Demo

Usage

  • Method chaining

    • All the method for typeset returns a self object to chaining itself.

       @"Hello typeset".typeset
          .match(@"Hello").fontSize(40)
          .match(@"type").purple
          .match(@"set").blue
          .string;
      

    call typeset method first and call string at last returns a NSAttributedString.

  • UILabel and UITextField support

    • Add typesetBlock to UILabel or UITextField, and you can directly set it's text style with:
     label.typesetBlock = TSBlock(fontSize(40)
                            .match(@"type").purple
                            .match(@"set").blue);
     label.text = @"Hello typeset, hello.";
    
     // If you type in this text field, it will color all the `1` in text field to red
     textField.typesetBlock = TSBlock(match(@"1").red);
    
  • Construct complicated NSMutableAttributedString

    TSAttributedString(@"Hello".red, @" ", @"World".blue);
    
  • Match part of string

    • Typeset providing a series of method to match part of your string, you can use these method to select part of your string, and add attribute to it.
     @"Hello".typeset.from(0).to(2).red.string;
     @"Hello".typeset.location(0).length(2).red.string;
     @"Hello".typeset.range(NSMakeRange(0,2)).red.string;
     @"Hello".typeset.match(@"He").red.string;
    

    These lines of code all make @"He" of @"Hello" to red

    Match Method Explain
    from(NSUInteger) to(NSUInteger)
    location(NSUInteger) length(NSUInteger)
    range(NSRange)
    match(NSString *) match the first substring
    matchWithOptions(NSString *, NSStringCompareOptions) match the first substring with options
    matchAll(NSString) match all the substring
    matchAllWithOptions(NSString *, NSStringCompareOptions) match all the substring with options
    all select all the string
    • Match with pattern
    Match Method Pattern
    matchAllWithPattern(NSString *pattern)
    matchAllWithPatternAndOptions(NSString *pattern, NSRegularExpressionOptions options)
    matchNumbers \d+
    matchLetters [a-zA-Z]+
    matchLanguage(NSString *language) \p{script=%@}
    matchChinese \p{[email protected]"Han"}
  • Convinient method

    • If you don't want to change some part of the string, and only want to change the color or the font, you call call these methods directly without calling typeset first
     @"Hello".red
     @"Hello".fontSize(20).red
    

References

Attributes

Dictionary Key Typeset Method
NSFontAttributeName font(NSString fontName, CGFloat size)
fontSize(CGFloat size)
fontName(NSString name)
regular light italic thin bold
NSForegroundColorAttributeName color(UIColor color)
hexColor(CGFloat hexColor)
black darkGray lightGray white gray red green blue cyan yellow magenta orange purple brown clear
NSKernAttributeName kern(CGFloat kern)
NSUnderlineStyleAttributeName underline(NSUnderlineStyle underline)
NSUnderlineColorAttributeName underlineColor(UIColor *underlineColor)
NSBaselineOffsetAttributeName baseline(CGFloat baseline)
NSStrikethroughStyleAttributeName strikeThrough(NSUnderlineStyle strikeThrough)
NSStrikethroughColorAttributeName strikeThroughColor(UIColor *underlineColor)
NSLinkAttributeName link(NSString *url)
NSLigatureAttributeName ligature(NSUInteger ligature)
NSStrokeColorAttributeName strokeColor(UIColor *strokeColor)
NSStrokeWidthAttributeName strokeWidth(CGFloat strokeWidth)
NSShadowAttributeName shadow(NSShadow *shadow)
NSTextEffectAttributeName textEffect(NSString *textEffect)
NSObliquenessAttributeName obliqueness(CGFloat obliqueness)
NSExpansionAttributeName expansion(CGFloat expansion)

NSParagraphStyle

Typeset Method
lineBreakMode(NSLineBreakMode lineBreakMode)
alignment(NSTextAlignment textAlignment)
lineSpacing(CGFloat lineSpacing)
paragraphSpacing(CGFloat paragraphSpacing)
firstLineHeadIndent(CGFloat firstLineHeadIndent)
headIndent(CGFloat headIndent)
tailIndent(CGFloat tailIndent)
minimumLineHeight(CGFloat minimumLineHeight)
maximumLineHeight(CGFloat maximumLineHeight)
lineHeightMultiple(CGFloat lineHeightMultiple)
paragraphSpacingBefore(CGFloat paragraphSpacingBefore)
hyphenationFactor(CGFloat hyphenationFactor)
defaultTabInterval(CGFloat defaultTabInterval)
baseWritingDirection(NSWritingDirection baseWritingDirection)
allowsDefaultTighteningForTruncation(BOOL allowsDefaultTighteningForTruncation)

Installation

CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like Typeset in your projects. See the Get Started section for more details.

Podfile

pod "Typeset"

Contribute

Feel free to open an issue or pull request, if you need help or there is a bug.

Contact

License

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

Todo

  • Documentation
  • More features
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].