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
NSRange
s, 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 *))attachment
Return 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.h
backgroundColor
Sets NSBackgroundColorAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))backgroundColor
Return 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.h
baselineOffset
Sets NSBaselineOffsetAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))baselineOffset
Return 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.h
characterShape
Sets NSCharacterShapeAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))characterShape
Return 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.h
cursor
Sets NSCursorAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSCursor *))cursor
Return 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.h
each
Helper method, used in conjunction with substring
to apply certain
attributes to each found substring.
- (instancetype)each
Return 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.h
expansion
Sets NSExpansionAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))expansion
Return 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.h
first
Helper method, used in conjunction with substring
to apply certain
attributes to a first found substring.
- (instancetype)first
Return 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.h
font
Sets NSFontAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( BOSFont *))font
Return 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.h
foregroundColor
Sets NSForegroundColorAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))foregroundColor
Return 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.h
glyphInfo
Sets NSGlyphInfoAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSGlyphInfo *))glyphInfo
Return 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.h
initWithAttributedString:
Returns a
- (instancetype)initWithAttributedString:(NSAttributedString *)string
Parameters
- string
Initial attributed string.
Return Value
Discussion
Returns a
Declared In
BOStringMaker.h
initWithString:
Returns a
- (instancetype)initWithString:(NSString *)string
Parameters
- string
Initial string.
Return Value
Discussion
Returns a
Declared In
BOStringMaker.h
kern
Sets NSKernAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))kern
Return 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.h
last
Helper method, used in conjunction with substring
to apply certain
attributes to a last found substring.
- (instancetype)last
Return 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.h
ligature
Sets NSLigatureAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))ligature
Return 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.h
link
Sets NSLinkAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( id ))link
Return 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.h
makeString
Returns NSAttributedString
instance.
- (NSAttributedString *)makeString
Return Value
NSAttributedString
instance, created with initial attributes (in
case if
Discussion
Returns NSAttributedString
instance.
Declared In
BOStringMaker.h
markedClauseSegment
Sets NSMarkedClauseSegmentAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))markedClauseSegment
Return 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.h
obliqueness
Sets NSObliquenessAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))obliqueness
Return 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.h
paragraphStyle
Sets NSParagraphStyleAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSParagraphStyle *))paragraphStyle
Return 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.h
range
Returns a block, which should contain attributes that are set for the range, passed to that block.
- (void ( ^ ) ( NSRange , void ( ^ ) ( void ) ))range
Discussion
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.h
regexpGroup
Method which applies certain attributes to regexp matching groups according
to rules, described in first
and each
methods.
- (void ( ^ ) ( NSString *, NSRegularExpressionOptions , void ( ^ ) ( void ) ))regexpGroup
Discussion
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.h
regexpMatch
Method which applies certain attributes to regexp matches according to rules,
described in first
and each
methods.
- (void ( ^ ) ( NSString *, NSRegularExpressionOptions , void ( ^ ) ( void ) ))regexpMatch
Discussion
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.h
shadow
Sets NSShadowAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSShadow *))shadow
Return 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.h
strikethroughColor
Sets NSStrikethroughColorAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))strikethroughColor
Return 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.h
strikethroughStyle
Sets NSStrikethroughStyleAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))strikethroughStyle
Return 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.h
stringRange
Returns a block, which should contain attributes that are set for the entire string.
- (void ( ^ ) ( void ( ^ ) ( void ) ))stringRange
Discussion
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.h
strokeColor
Sets NSStrokeColorAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))strokeColor
Return 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.h
strokeWidth
Sets NSStrokeWidthAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))strokeWidth
Return 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.h
substring
Method which applies certain attributes to substrings according to rules,
described in first
and each
methods.
- (void ( ^ ) ( NSString *, void ( ^ ) ( void ) ))substring
Discussion
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.h
superscript
Sets NSSuperscriptAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))superscript
Return 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.h
textAlternatives
Sets NSTextAlternativesAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSTextAlternatives *))textAlternatives
Return 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.h
textEffect
Sets NSTextEffectAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSString *))textEffect
Return 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.h
toolTip
Sets NSToolTipAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSString *))toolTip
Return 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.h
underlineColor
Sets NSUnderlineColorAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( BOSColor *))underlineColor
Return 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.h
underlineStyle
Sets NSUnderlineStyleAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))underlineStyle
Return 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.h
verticalGlyphForm
Sets NSVerticalGlyphFormAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( NSNumber *))verticalGlyphForm
Return 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.h
with
Semantic filler. Returns self
, so effectively, does nothing.
- (instancetype)with
Return Value
self
.
Discussion
Semantic filler. Returns self
, so effectively, does nothing.
Declared In
BOStringMaker.h
writingDirection
Sets NSWritingDirectionAttributeName
attribute.
- (BOStringAttribute *( ^ ) ( id ))writingDirection
Return 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