NSAttributedString+CCLFormat 1.2.0

NSAttributedString+CCLFormat 1.2.0

TestsTested
LangLanguage Obj-CObjective C
License BSD
ReleasedLast Release Feb 2016

Maintained by Kyle Fuller.


Downloads

Total192,097
Week0
Month0

Installs

Apps790
Test Targets100
Watch Apps3
powered by Segment

GitHub

Stars61
Watchers2
Forks10
Issues0
Contributors5
Pull Requests1

Code

Files2
LOCLines of Code 150


An extension to NSAttributedString for creating attributed strings by using a given format string as a template into which the remaining argument values are substituted. This is helpful for using in conjunction with internationalisation.

@interface NSAttributedString (CCLFormat)

+ (NSAttributedString *)attributedStringWithFormat:(NSString *)format, ...;

@end

Usage

NSAttributedString *blue, *green, *never, *result;

blue = [[NSAttributedString alloc] initWithString:@"Blue" attributes:@{
    NSFontAttributeName: [UIFont boldSystemFontOfSize:16.0f],
    NSForegroundColorAttributeName: [UIColor blueColor],
}];

green = [[NSAttributedString alloc] initWithString:@"Green" attributes:@{
    NSFontAttributeName: [UIFont boldSystemFontOfSize:16.0f],
    NSForegroundColorAttributeName: [UIColor greenColor],
}];

never = [[NSAttributedString alloc] initWithString:@"never" attributes:@{
    NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
}];

result = [NSAttributedString attributedStringWithFormat:@"%@ and %@ must %@ be seen", blue, green, never];

Installation

CocoaPods is the recommended way to add NSAttributedString+CCLFormat to your project.

Here's an example podfile that installs NSAttributedString+CCLFormat.

Podfile

pod 'NSAttributedString+CCLFormat'

License

NSAttributedString+CCLFormat is released under the BSD license. See LICENSE.