Created
April 9, 2013 10:15
-
-
Save maxhuk/5344641 to your computer and use it in GitHub Desktop.
Comfortable multi-part NSAttributedString composition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSAttributedString+Compose.h | |
// | |
// Created by Maksym Huk on 3/31/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSAttributedString (Compose) | |
// [ ["",{}], ["",{}], ... ] | |
+ (NSAttributedString *)attributedStringWithParts:(NSArray *)parts; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSAttributedString+Compose.m | |
// | |
// Created by Maksym Huk on 3/31/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import "NSAttributedString+Compose.h" | |
@implementation NSAttributedString (Compose) | |
+ (NSAttributedString *)attributedStringWithParts:(NSArray *)parts | |
{ | |
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init]; | |
for (NSArray *part in parts) { | |
[string appendAttributedString:[[NSAttributedString alloc] initWithString:part[0] attributes:part[1]]]; | |
} | |
return string; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment