Created
February 3, 2016 06:11
-
-
Save ryu1/ee52ff40fbed5bb8cfda to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // NSMutableAttributedString+Extension.h | |
| // | |
| // Created by Ryuichi Ishitsuka on 2016/01/08. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface NSMutableAttributedString (Extension) | |
| /** | |
| * imageを文字列に挿入します。 | |
| * | |
| * @param icon 挿入するアイコン画像 | |
| * @param bounds 挿入枠内でのimageの座標 | |
| */ | |
| -(void)insertIconImage:(UIImage*)icon bounds:(CGRect)bounds; | |
| @end |
This file contains hidden or 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
| // | |
| // NSMutableAttributedString+Extension.m | |
| // | |
| // Created by Ryuichi Ishitsuka on 2016/01/08. | |
| // | |
| #import "NSMutableAttributedString+Extension.h" | |
| @implementation NSMutableAttributedString (Extension) | |
| -(void)insertIconImage:(UIImage*)icon bounds:(CGRect)bounds | |
| { | |
| NSTextAttachment *at = [[NSTextAttachment alloc] init]; | |
| at.image = icon; | |
| at.bounds = bounds; | |
| NSAttributedString *ns = [NSAttributedString attributedStringWithAttachment:at]; | |
| // アノテーションが残ってしまうから、文字列中から削除 | |
| NSRange range = [self.string rangeOfString:@"アノテーション"]; | |
| [self replaceCharactersInRange:range withString:@""]; | |
| // 同じところに、iconを追加 | |
| [self insertAttributedString:ns atIndex:range.location]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment