inline HTML in UILable
// UILabel + Html.h
#import
@interface UILabel (Html)
-(void) setHTMLText:(NSString*)htmlText;
@end
// UILabel+appLabel.m
#import "UILabel+appLabel.h"
@implementation UILabel (Html)
-(void) setHTMLText:(NSString*)htmlText{
dispatch_async(dispatch_get_main_queue(), ^{
NSError *err = nil;
self.attributedText = [[NSAttributedString alloc] initWithData: [htmlText dataUsingEncoding:NSUTF8StringEncoding]
options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
documentAttributes: nil
error: &err];
if(err)
NSLog(@"Unable to parse label text: %@", err);
});
}
@end
Comments
Post a Comment