BOStringMaker Class Reference
| Inherits from | NSObject |
| Declared in | BOStringMaker.h |
Overview
This class “resolves” maker block.
Maker block is a list of instructions how to create an NSAttributedString.
Example:
NSAttributedString *result = [@"string" makeString:^(BOStringMaker *make) {
make.font([UIFont systemFontOfSize:12]).with.stringRange();
make.foregroundColor([UIColor greenColor]).with.range(NSMakeRange(0, 5));
make.backgroundColor([UIColor blueColor]).range(NSMakeRange(0, 3));
}];
Attributes are stored as BOStringAttribute objects in the internal array. After all attributes are processed, makeString method resolves collisions with the following algorithm:
it maps array of BOStringAttribute objects into a dictionary:
@{NSRange => @[@{attribute name => attribute value}, ...], ...}
in this example attribute name is an NSAttributedString attribute name
i.e. NSFontAttributeName, attribute value is it’s value, i.e. UIFont
instance.
it sorts all the attributes by their
NSRanges, so that ranges with the same start indexes and longer length have priority over the ones with a shorter range.it applies all attributes with
[NSMutableAttributedString addAttributes:range:]method.
With this algorithm attributes are applied from left to right, so in case if you write something like:
make.foregroundColor([UIColor blueColor]).range(NSMakeRange(1, 2));
make.foregroundColor([UIColor redColor]).stringRange();
it makes sure that redColor will be applied first and blueColor second.
Tasks
Initializers
String maker
Range modifiers
Attributed string helper methods
Attributes
-
– font -
– paragraphStyle -
– foregroundColor -
– backgroundColor -
– ligature -
– kern -
– strikethroughStyle -
– underlineStyle -
– strokeColor -
– strokeWidth -
– shadow -
– verticalGlyphForm -
– textEffect -
– attachment -
– link -
– baselineOffset -
– underlineColor -
– strikethroughColor -
– obliqueness -
– expansion -
– writingDirection -
– superscript -
– cursor -
– toolTip -
– characterShape -
– glyphInfo -
– markedClauseSegment -
– textAlternatives
Instance Methods
attachment
Sets NSAttachmentAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSTextAttachment *))attachmentReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSAttachmentAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hbackgroundColor
Sets NSBackgroundColorAttributeName attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))backgroundColorReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSBackgroundColorAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hbaselineOffset
Sets NSBaselineOffsetAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))baselineOffsetReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSBaselineOffsetAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hcharacterShape
Sets NSCharacterShapeAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))characterShapeReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSCharacterShapeAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hcursor
Sets NSCursorAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSCursor *))cursorReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSCursorAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.heach
Helper method, used in conjunction with substring to apply certain
attributes to each found substring.
- (instancetype)eachReturn Value
self. After invoking this method, you must call substring.
Discussion
Helper method, used in conjunction with substring to apply certain
attributes to each found substring.
Example:
NSAttributedString *result = [@"abababa" makeString:^(BOStringMaker *make) {
make.each.substring(@"a", ^{
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
});
}];
Declared In
BOStringMaker.hexpansion
Sets NSExpansionAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))expansionReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSExpansionAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hfirst
Helper method, used in conjunction with substring to apply certain
attributes to a first found substring.
- (instancetype)firstReturn Value
self. After invoking this method, you must call substring.
Discussion
Helper method, used in conjunction with substring to apply certain
attributes to a first found substring.
Example:
NSAttributedString *result = [@"abababa" makeString:^(BOStringMaker *make) {
make.first.substring(@"a", ^{
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
});
}];
Declared In
BOStringMaker.hfont
Sets NSFontAttributeName attribute.
- (BOStringAttribute *( ^ ) ( BOSFont *))fontReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range:
NSAttributedString *result = [stringVar makeString:^(BOStringMaker *make) {
make.font([UIFont fontOfSize:12]).with.range(NSMakeRange(0, 5));
}];
Discussion
Sets NSFontAttributeName attribute.
See Also
BOStringAttribute for more information.
Declared In
BOStringMaker.hforegroundColor
Sets NSForegroundColorAttributeName attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))foregroundColorReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSForegroundColorAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hglyphInfo
Sets NSGlyphInfoAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSGlyphInfo *))glyphInfoReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSGlyphInfoAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hinitWithAttributedString:
Returns a
- (instancetype)initWithAttributedString:(NSAttributedString *)stringParameters
- string
Initial attributed string.
Return Value
Discussion
Returns a
Declared In
BOStringMaker.hinitWithString:
Returns a
- (instancetype)initWithString:(NSString *)stringParameters
- string
Initial string.
Return Value
Discussion
Returns a
Declared In
BOStringMaker.hkern
Sets NSKernAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))kernReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSKernAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hlast
Helper method, used in conjunction with substring to apply certain
attributes to a last found substring.
- (instancetype)lastReturn Value
self. After invoking this method, you must call substring.
Discussion
Helper method, used in conjunction with substring to apply certain
attributes to a last found substring.
Example:
NSAttributedString *result = [@"abababa" makeString:^(BOStringMaker *make) {
make.last.substring(@"a", ^{
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
});
}];
Declared In
BOStringMaker.hligature
Sets NSLigatureAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))ligatureReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSLigatureAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hlink
Sets NSLinkAttributeName attribute.
- (BOStringAttribute *( ^ ) ( id ))linkReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSLinkAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hmakeString
Returns NSAttributedString instance.
- (NSAttributedString *)makeStringReturn Value
NSAttributedString instance, created with initial attributes (in
case if
Discussion
Returns NSAttributedString instance.
Declared In
BOStringMaker.hmarkedClauseSegment
Sets NSMarkedClauseSegmentAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))markedClauseSegmentReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSMarkedClauseSegmentAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hobliqueness
Sets NSObliquenessAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))obliquenessReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSObliquenessAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hparagraphStyle
Sets NSParagraphStyleAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSParagraphStyle *))paragraphStyleReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSParagraphStyleAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hrange
Returns a block, which should contain attributes that are set for the range, passed to that block.
- (void ( ^ ) ( NSRange , void ( ^ ) ( void ) ))rangeDiscussion
Returns a block, which should contain attributes that are set for the range, passed to that block.
Example:
NSAttributedString *result = [@"string" makeString:^(BOStringMaker *make) {
make.with.range(NSMakeRange(0, 5), ^{
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
});
}];
All three attributes above will be applied for the range (0, 5).
Declared In
BOStringMaker.hregexpGroup
Method which applies certain attributes to regexp matching groups according
to rules, described in first and each methods.
- (void ( ^ ) ( NSString *, NSRegularExpressionOptions , void ( ^ ) ( void ) ))regexpGroupDiscussion
Method which applies certain attributes to regexp matching groups according
to rules, described in first and each methods.
Example:
NSAttributedString *result = [@"aab ab ab" makeString:^(BOStringMaker *make) {
make.each.regexpGroup(@"\\s(a\\w)", NSRegularExpressionCaseInsensitive, ^{
make.backgroundColor([UIColor blueColor]);
});
make.first.regexpGroup(@"a(ab)", 0, ^{
make.foregoundColor([UIColor greenColor]);
});
}];
Declared In
BOStringMaker.hregexpMatch
Method which applies certain attributes to regexp matches according to rules,
described in first and each methods.
- (void ( ^ ) ( NSString *, NSRegularExpressionOptions , void ( ^ ) ( void ) ))regexpMatchDiscussion
Method which applies certain attributes to regexp matches according to rules,
described in first and each methods.
Example:
NSAttributedString *result = [@"aab ab ab" makeString:^(BOStringMaker *make) {
make.each.regexpMatch(@"\\w{2}", NSRegularExpressionCaseInsensitive, ^{
make.backgroundColor([UIColor blueColor]);
});
make.first.regexpMatch(@"a[^b]", 0, ^{
make.foregoundColor([UIColor greenColor]);
});
}];
Declared In
BOStringMaker.hshadow
Sets NSShadowAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSShadow *))shadowReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSShadowAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hstrikethroughColor
Sets NSStrikethroughColorAttributeName attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))strikethroughColorReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSStrikethroughColorAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hstrikethroughStyle
Sets NSStrikethroughStyleAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))strikethroughStyleReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSStrikethroughStyleAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hstringRange
Returns a block, which should contain attributes that are set for the entire string.
- (void ( ^ ) ( void ( ^ ) ( void ) ))stringRangeDiscussion
Returns a block, which should contain attributes that are set for the entire string.
Example:
NSAttributedString *result = [@"string" makeString:^(BOStringMaker *make) {
make.with.stringRange(^{
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
});
}];
All three attributes above will be applied for a whole string. This method is equivalent to the following invocation:
NSAttributedString *result = [stringVar makeString:^(BOStringMaker *make) {
make.with.range(NSMakeRange(0, [stringVar length]), ^{
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
});
}];
In fact, by default all attributes are applied to a whole string, so if you want a shorter code, you can write something like this:
NSAttributedString *result = [stringVar makeString:^(BOStringMaker *make) {
make.font([UIFont systemFontOfSize:12]);
make.foregroundColor([UIColor greenColor]);
make.backgroundColor([UIColor blueColor]);
}];
However for the sake of readability, you still might want to use this method.
See Also
BOStringAttribute to learn more about attributes application - range.
Declared In
BOStringMaker.hstrokeColor
Sets NSStrokeColorAttributeName attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))strokeColorReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSStrokeColorAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hstrokeWidth
Sets NSStrokeWidthAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))strokeWidthReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSStrokeWidthAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hsubstring
Method which applies certain attributes to substrings according to rules,
described in first and each methods.
- (void ( ^ ) ( NSString *, void ( ^ ) ( void ) ))substringDiscussion
Method which applies certain attributes to substrings according to rules,
described in first and each methods.
Example:
NSAttributedString *result = [@"abababa" makeString:^(BOStringMaker *make) {
make.each.substring(@"a", ^{
make.backgroundColor([UIColor blueColor]);
});
make.first.substring(@"ab", ^{
make.foregoundColor([UIColor greenColor]);
});
}];
Declared In
BOStringMaker.hsuperscript
Sets NSSuperscriptAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))superscriptReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSSuperscriptAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.htextAlternatives
Sets NSTextAlternativesAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSTextAlternatives *))textAlternativesReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSTextAlternativesAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.htextEffect
Sets NSTextEffectAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSString *))textEffectReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSTextEffectAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.htoolTip
Sets NSToolTipAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSString *))toolTipReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSToolTipAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hunderlineColor
Sets NSUnderlineColorAttributeName attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))underlineColorReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSUnderlineColorAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hunderlineStyle
Sets NSUnderlineStyleAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))underlineStyleReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSUnderlineStyleAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hverticalGlyphForm
Sets NSVerticalGlyphFormAttributeName attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))verticalGlyphFormReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSVerticalGlyphFormAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.hwith
Semantic filler. Returns self, so effectively, does nothing.
- (instancetype)withReturn Value
self.
Discussion
Semantic filler. Returns self, so effectively, does nothing.
Declared In
BOStringMaker.hwritingDirection
Sets NSWritingDirectionAttributeName attribute.
- (BOStringAttribute *( ^ ) ( id ))writingDirectionReturn Value
BOStringAttribute instance, in case if you want to change attribute’s range.
Discussion
Sets NSWritingDirectionAttributeName attribute.
See Also
- font for more information.
BOStringAttribute for more information.
Declared In
BOStringMaker.h