TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | May 2017 |
Maintained by Draveness, draveness.
Typeset makes it easy to create NSAttributedString
@"Hello typeset".typeset
.match(@"Hello").fontSize(40)
.match(@"type").purple
.match(@"set").blue
.string;
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 callstring
at last returns aNSAttributedString
.
UILabel
and UITextField
support
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
@"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 Method | Pattern |
---|---|
matchAllWithPattern(NSString *pattern) |
|
matchAllWithPatternAndOptions(NSString *pattern, NSRegularExpressionOptions options) |
|
matchNumbers |
\d+ |
matchLetters |
[a-zA-Z]+ |
matchLanguage(NSString *language) |
\p{script=%@} |
matchChinese |
\p{script=@"Han"} |
Convinient method
typeset
first@"Hello".red
@"Hello".fontSize(20).red
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) |
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) |
pod "Typeset"
Feel free to open an issue or pull request, if you need help or there is a bug.
Typeset is available under the MIT license. See the LICENSE file for more info.