Skip to content

Instantly share code, notes, and snippets.

@maxhuk
Created April 9, 2013 10:15
Show Gist options
  • Save maxhuk/5344641 to your computer and use it in GitHub Desktop.
Save maxhuk/5344641 to your computer and use it in GitHub Desktop.
Comfortable multi-part NSAttributedString composition.
//
// 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
//
// 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