mattdonnelly / mdhtmllabel Goto Github PK
View Code? Open in Web Editor NEW:link: A lightweight class for rendering text containing HTML tags on iOS 6.0+
License: MIT License
:link: A lightweight class for rendering text containing HTML tags on iOS 6.0+
License: MIT License
Maybe someone can help me!
I get some html Text from my Server and it should be shown on my Device like this:
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
but instead it looks like this:
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
As you can see, there is no line break, why?
This is the Code:
MDHTMLLabel *htmlLabel = [[MDHTMLLabel alloc] init];
htmlLabel.delegate = self;
htmlLabel.numberOfLines = 0;
htmlLabel.lineBreakMode = NSLineBreakByTruncatingTail;
htmlLabel.font = [UIFont fontWithName:@"Arial" size:12.0f];
htmlLabel.htmlText = item.text;
htmlLabel.linkAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
NSFontAttributeName: [UIFont boldSystemFontOfSize:htmlLabel.font.pointSize],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
htmlLabel.activeLinkAttributes = @{NSForegroundColorAttributeName: [UIColor redColor],
NSFontAttributeName: [UIFont boldSystemFontOfSize:htmlLabel.font.pointSize],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
[self addSubview:htmlLabel];
Here is the Html Text:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua.<br /><br /> At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua.<br /><br /> At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
font size without font face doesn't work
I used to be able to include custom fonts within the text (with icon symbols), like so:
<a href=\”http://example.com\”><font face=\”customappfont\”>O</font>Open Website</a>
This still works. However, on tap, the custom font returns to whatever the main font is. So it looks like:
OOpen Website
rather than:
(symbol)Open Website
(void)setHtmlText:(NSString *)htmlText
{
if ([_htmlText isEqualToString:htmlText])
{
return;
}
_htmlText = [htmlText copy];
_htmlAttributedText = nil;
if (_htmlText)
{
//(this code seems needless( change a param). when i comment it, the demo works well)************
// htmlText = [_htmlText stringByReplacingOccurrencesOfString:@"
" withString:@"\n"];
if (self.autoDetectUrls)
{
//(this code seems needless(change a param), too. when i comment it, the demo works well)***********
// htmlText = [self detectURLsInText:_htmlText];
}
[self extractStyleFromText:_htmlText];
}
else
{
self.styleComponents = nil;
self.plainText = nil;
self.links = [NSMutableArray array];
}
[self setNeedsFramesetter];
[self setNeedsDisplay];
[self invalidateIntrinsicContentSize];
}
MDHTMLLabel doesn't handle HTML entities, for example < and >
Say I want to display this exact string in MDHTMLLabel:
"1 < 2, I <3 MDHTMLLabel, 2 > 1"
label.htmlText = @"1 < 2, I <3 MDHTMLLabel, 2 > 1";
You can't. You'll end up with "1 1", see the attached screen shot.
It'd expected this to work:
label.htmlText = @"1 < 2, I <3 MDHTMLLabel, 2 > 1";
But it will appear the same!
The issue is here:
https://github.com/mattdonnelly/MDHTMLLabel/blob/master/MDHTMLLabel/MDHTMLLabel.m#L1339
The code is decoding the HTML entities before it finds styles and extract links.
I think the correct fix is to move the code to decode the HTML entities to after it finds styles and extract links. But just moving the code in MDHTMLLabel to decode the HTML after we do the detection won't work, as the offsets for all the links and style components will be incorrect.
Note that RTLabel seems to have a similar bug, see honcheng/RTLabel#47
I want to be able to have a label with attributed text, with combined fonts. In my case, I would be using a normal font and a custom symbol font.
For instance, the text:
See your items in the (*) Favorites section
.. with (*) Favorites
being a single link and (*)
being a letter from a custom font.
Is there a way to do this with MDHTMLLabel?
if I set htmlText as <span> </span>
it appears  
in label.
At the first, I must be thanks for your great code for us! it's very helpful!
I set some shadow on Label, and put it into a tablecell when I long click the label and move it, the shadow is cleared
I feel if set the property "Highlighted" to "NO" is not work, I must be do following
bodyLabel.highlighted = YES;
bodyLabel.highlightedShadowColor = bodyLabel.shadowColor;
bodyLabel.highlightedShadowOffset = bodyLabel.shadowOffset;
bodyLabel.highlightedShadowRadius = bodyLabel.shadowRadius;
bodyLabel.highlightedTextColor = bodyLabel.textColor;
I see the crash, add to kDemoText in DemoViewController.m
* thread #1: tid = 0x43ef3c, 0x0196d3e2 CoreFoundation`CFRunArrayGetValueAtIndex + 66, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xd6eb000)
frame #0: 0x0196d3e2 CoreFoundation`CFRunArrayGetValueAtIndex + 66
frame #1: 0x019bb1c8 CoreFoundation`CFAttributedStringGetAttribute + 136
frame #2: 0x0000b691 MDHTMLLabel`-[MDHTMLLabel applyBoldStyleToText:range:](self=0x08e76ff0, _cmd=0x00017338, text=0x08c682b0, range=NSRange at 0xbfffa858) + 97 at MDHTMLLabel.m:1195
* frame #3: 0x00007c52 MDHTMLLabel`-[MDHTMLLabel applyStylesToString:](self=0x08e76ff0, _cmd=0x00016e86, string=0x08c63e40) + 2098 at MDHTMLLabel.m:847
frame #4: 0x00004c51 MDHTMLLabel`-[MDHTMLLabel htmlAttributedText](self=0x08e76ff0, _cmd=0x00016ecd) + 97 at MDHTMLLabel.m:445
frame #5: 0x00004e5a MDHTMLLabel`-[MDHTMLLabel framesetter](self=0x08e76ff0, _cmd=0x00017149) + 106 at MDHTMLLabel.m:475
frame #6: 0x0000f068 MDHTMLLabel`-[MDHTMLLabel textRectForBounds:limitedToNumberOfLines:](self=0x08e76ff0, _cmd=0x00a4676d, bounds=<unavailable>, numberOfLines=0) + 456 at MDHTMLLabel.m:1528
frame #7: 0x0040962e UIKit`-[UILabel _intrinsicSizeWithinSize:] + 173
frame #8: 0x00409751 UIKit`-[UILabel intrinsicContentSize] + 91
frame #9: 0x0000fa53 MDHTMLLabel`-[MDHTMLLabel intrinsicContentSize](self=0x08e76ff0, _cmd=0x00a295df) + 67 at MDHTMLLabel.m:1582
frame #10: 0x008e37ef UIKit`-[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 36
frame #11: 0x008e3480 UIKit`-[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 511
frame #12: 0x008e97bf UIKit`-[UIView(AdditionalLayoutSupport) updateConstraints] + 110
frame #13: 0x00409579 UIKit`-[UILabel updateConstraints] + 189
frame #14: 0x008e9058 UIKit`-[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 239
frame #15: 0x008e91d6 UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
frame #16: 0x008e9157 UIKit`__UIViewRecursionHelper + 40
frame #17: 0x01921c69 CoreFoundation`CFArrayApplyFunction + 57
frame #18: 0x008e8ffc UIKit`-[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
frame #19: 0x008e91d6 UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
frame #20: 0x008e9157 UIKit`__UIViewRecursionHelper + 40
frame #21: 0x01921c69 CoreFoundation`CFArrayApplyFunction + 57
frame #22: 0x008e8ffc UIKit`-[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
frame #23: 0x008e91d6 UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
frame #24: 0x008dd878 UIKit`__62-[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke + 43
frame #25: 0x0133e68c Foundation`-[NSISEngine withBehaviors:performModifications:] + 107
frame #26: 0x011ce3c5 Foundation`-[NSISEngine withAutomaticOptimizationDisabled:] + 48
frame #27: 0x008dd590 UIKit`-[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded] + 225
frame #28: 0x008dd467 UIKit`-[UIWindow(UIConstraintBasedLayout) layoutSublayersOfLayer:] + 90
frame #29: 0x0159d82b libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #30: 0x03deb45a QuartzCore`-[CALayer layoutSublayers] + 148
frame #31: 0x03ddf244 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380
frame #32: 0x03deb3a5 QuartzCore`-[CALayer layoutIfNeeded] + 160
frame #33: 0x0037cae3 UIKit`-[UIViewController window:setupWithInterfaceOrientation:] + 304
frame #34: 0x00292aa7 UIKit`-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
frame #35: 0x00291646 UIKit`-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
frame #36: 0x00291518 UIKit`-[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
frame #37: 0x002915a0 UIKit`-[UIWindow _setRotatableViewOrientation:duration:force:] + 67
frame #38: 0x0029063a UIKit`__57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
frame #39: 0x0029059c UIKit`-[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
frame #40: 0x002912f3 UIKit`-[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
frame #41: 0x002948e6 UIKit`-[UIWindow setDelegate:] + 449
frame #42: 0x0036eb77 UIKit`-[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
frame #43: 0x0028a474 UIKit`-[UIWindow addRootViewControllerViewIfPossible] + 591
frame #44: 0x0028a5ef UIKit`-[UIWindow _setHidden:forced:] + 312
frame #45: 0x0028a86b UIKit`-[UIWindow _orderFrontWithoutMakingKey] + 49
frame #46: 0x002953c8 UIKit`-[UIWindow makeKeyAndVisible] + 65
frame #47: 0x00245bc0 UIKit`-[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 2097
frame #48: 0x0024a667 UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
frame #49: 0x0025ef92 UIKit`-[UIApplication handleEvent:withNewEvent:] + 3517
frame #50: 0x0025f555 UIKit`-[UIApplication sendEvent:] + 85
frame #51: 0x0024c250 UIKit`_UIApplicationHandleEvent + 683
frame #52: 0x03975f02 GraphicsServices`_PurpleEventCallback + 776
frame #53: 0x03975a0d GraphicsServices`PurpleEventCallback + 46
frame #54: 0x018fbca5 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
frame #55: 0x018fb9db CoreFoundation`__CFRunLoopDoSource1 + 523
frame #56: 0x0192668c CoreFoundation`__CFRunLoopRun + 2156
frame #57: 0x019259d3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #58: 0x019257eb CoreFoundation`CFRunLoopRunInMode + 123
frame #59: 0x00249d9c UIKit`-[UIApplication _run] + 840
frame #60: 0x0024bf9b UIKit`UIApplicationMain + 1225
frame #61: 0x00002c1d MDHTMLLabel`main(argc=1, argv=0xbfffedf8) + 141 at main.m:33
MDHTMLLable.m line at 660.
linkButton.URL = [NSURL URLWithString:[linkableComponents.attributes objectForKey:@"href"]];
The URL is null if there is a unicode-character (like Korean Lang.).
So, I fixed it to
NSString *attributeUrl = [linkableComponents.attributes objectForKey:@"href"];
attributeUrl = [attributeUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *aUrl = [NSURL URLWithString:attributeUrl];
linkButton.URL = aUrl;
Thank you.
Hello Matt,
Thanks In Advance...
We are using MDHTMLLabel for display below html string.
You are now manager of <4070Testing>.
we have 2 scenarios..
I needed to use superscript/subscript but MDHTMLLabel doesn't support it, so I implemented it and though it works, it doesn't for iOS9.x. Texts are not subscripted nor superscripted. I've reviewed the code but can't make it where the problem could be.
This is the code I'm using that I implemented, showing subscript only:
- (void)applySubscriptToText:(CFMutableAttributedStringRef)text
range:(NSRange)range {
/* Because Helvetica Neue doesn't handle subscript AND because CT added kCTSuperscriptAttributeName key until ios11, this code is commented out:
CFAttributedStringSetAttribute(text, CFRangeFromNSRange(range), kCTSuperscriptAttributeName, (__bridge CFTypeRef)(@-1));
*/
NSMutableAttributedString *attributedString = (__bridge NSMutableAttributedString *)(text);
UIFont *subScriptFont = [UIFont fontWithName:self.font.fontName size:self.font.pointSize * 0.6];
[attributedString addAttribute:NSFontAttributeName value:subScriptFont range:range];
[attributedString addAttribute:NSBaselineOffsetAttributeName value:@(-1.5) range:range];
}
If you use iOS11 you can use the commented code and discard the rest (or you can leave the code as is and it will work for iOS > 9.x), otherwise it only works for iOS > 9.x.
This makes it centered:
htmlLabel.textAlignment = NSTextAlignmentRight;
while this aligns it to the right:
htmlLabel.textAlignment = NSTextAlignmentCenter;
Left seems to work.
According to current senario, I have received html string from server and i am using your library to parse html content. all things are working fine except inline image. so can you please help me how i can provide support to display inline image in UILabel?
Thanks in advance
i'm having memory problems allocating MDHTMLLabels in TableCellViews.
have you experience this kind of errors?
Hello @mattdonnelly
I have set html as following:
123
<div>
<div contenteditable="false" class="embed link clearfix has-photo">
<a href="http://www.google.com" target="_blank" class="embedded-link" title="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.">
<div class="img-wrapper longer-width">
<img src="http://www.google.com/favicon.ico" class="embedded-favicon" alt="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.">
</div>
<div class="detail">
<span class="embedded-title">Google</span>
<div class="origin-link">www.google.com</div>
</div>
</a>
</div>
<br>
<div>
<span style="line-height: 1.3;">abc</span>
<br>
</div>
</div>
But this lable not display correct html style.
@property(strong, nonatomic) IBOutlet MDHTMLLabel *customMessageLabel;
_customMessageLabel.delegate = self;
_customMessageLabel.numberOfLines = 3;
[_customMessageLabel sizeToFit];
_customMessageLabel.verticalAlignment = MDHTMLLabelVerticalAlignmentCenter;
_customMessageLabel.linkAttributes = @{ NSForegroundColorAttributeName: [UIColor blueColor],
NSFontAttributeName: [UIFont boldSystemFontOfSize:_customMessageLabel.font.pointSize],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle) };
_customMessageLabel.activeLinkAttributes = @{ NSForegroundColorAttributeName: [UIColor redColor],
NSFontAttributeName: [UIFont boldSystemFontOfSize:_customMessageLabel.font.pointSize],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle) };
_customMessageLabel.htmlText = @"Welcome to clickable link clickable link - <a href='http://store.apple.com'>link to apple store</a> <a href='http://www.google.com'>link to google</a> <a href='http://www.yahoo.com'>link to yahoo</a> <a href='https://github.com/honcheng/RTLabel'>link to RTLabel in GitHub</a> <a href='http://www.wiki.com'>link to wiki.com website</a> NSAttributtedString have a property string and it is read only property you can not change it NSAttributtedString have a property string and it is read only property you can not change it NSAttributtedString have a property string and it is read only property you can not change it";
_customMessageLabel.truncationTokenString = @"...More";
_customMessageLabel.truncationTokenStringAttributes = @{
NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:_customMessageLabel.font,
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
NSLinkAttributeName: [NSURL URLWithString:@"http://more.com"]
};
Link :StackOverFlow
Can I configured the Label to not detect the emails because it is adding the "mailto:" and don't want this.
Thanks
I noticed a typo in your README file. I’ve highlighted it in bold italics for your convenience below.
…links inside the label to represent HTML _achor_ tags and allows you to detect…
MDHTMLLabel is great, thank you!
But HTML like this will cause problems:
<a href='http://www.google.com'>google.com</a>
On my console:
MyApp(2800,0x44df1a8) malloc: *** mach_vm_map(size=925696) failed (error code=3)
error: can't allocate region
set a breakpoint in malloc_error_break to debug
MyApp(2800,0x44df1a8) malloc: *** mach_vm_map(size=925696) failed (error code=3)
error: can't allocate region
set a breakpoint in malloc_error_break to debug
ShopStyle_Dev(2800,0x44df1a8) malloc: *** mach_vm_map(size=925696) failed (error code=3)
error: can't allocate region
set a breakpoint in malloc_error_break to debug
MyApp(2800,0x44df1a8) malloc: *** mach_vm_map(size=618496) failed (error code=3)
error: can't allocate region
set a breakpoint in malloc_error_break to debug
We'll run out of memory.
looks like [MDHTMLLabel detectURLsInText] has a bug and we get stuck incorrectly wrapping a url over and over.
I've got a patch, I'll make a pull request to see what you think.
Replace 'MDHTMLLabel/MDHTMLLabel-Prefix.pch' with 'Demo/MDHTMLLabelDemo-Prefix.pch' in Build Settings ->Apple LLVM 6.0 Language ->Prefix Header
thanks for the update, it's works really good.
i'm thinking now in the idea of create , with user defined attributes.
i'm playing with your code and it seems to be easy to implement it.
you write a good code objectiveC code.
i'm not an objectiveC developer, i'm feel more confortable in ruby (rubymotion)
thanks again for share your code, it's great.
Hi I've tried displaying some very large texts with MDHTMLLabel (about 24000 characters) and the result was a blank.
I have the label inside a scrollview and I could get the correct content height (from sizeToFit) so that I could scroll to read everything.
The text was nowhere to be seen, although I could scroll to the end (to where it should be).
I also tried setting the background color to see the label bounds, but the label doesn't show up at all.
Also, reducing the amount of characters (to about 21000-22000) seems to work ok.
Any ideas?
Thanks!
hi, i got a crash when i parse such html <img alt="" src="about:blank" /> ...
as you see, alt="", so when the code goes to the extractStyleFromText method,
the follow codes in line 1460 may causes crash:
value = [value stringByReplacingOccurrencesOfString:@""" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 1)];
value = [value stringByReplacingOccurrencesOfString:@""" withString:@"" options:NSLiteralSearch range:NSMakeRange([value length]-1, 1)];
// After the two statements ran, the value will be EMPTY, so the next line will CAUSES CRASH...
value = [value stringByReplacingOccurrencesOfString:@"'" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 1)];
value = [value stringByReplacingOccurrencesOfString:@"'" withString:@"" options:NSLiteralSearch range:NSMakeRange([value length]-1, 1)];
value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
My solution is subclass your label and override this method replace them by:
value = value.length == 0? value:[value stringByReplacingOccurrencesOfString:@""" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 1)];
value = value.length == 0? value:[value stringByReplacingOccurrencesOfString:@""" withString:@"" options:NSLiteralSearch range:NSMakeRange([value length]-1, 1)];
value = value.length == 0? value:[value stringByReplacingOccurrencesOfString:@"'" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 1)];
value = value.length == 0? value:[value stringByReplacingOccurrencesOfString:@"'" withString:@"" options:NSLiteralSearch range:NSMakeRange([value length]-1, 1)];
value = value.length == 0? value:[value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
BTW, the special tag like  ; &rdquo; you havent translate them, so i wish you can handle them...LOL
BTW again, may you supply a method just give me the plaintext extra from html? thx!!!
Hi
Its great one, but i'm asking how to take the CGSize for htmlText to set the frame depends on it
I used this one but it doesn't make what I need
NSString *titlec = [NSString stringWithFormat:@"<b>%@</b> %@",thecomment.user.username,thecomment.text];
CGSize size = [self frameForText:titlec sizeWithFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:12.0] constrainedToSize:CGSizeMake(300.f, CGFLOAT_MAX)];
-(CGSize)frameForText:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size{
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
nil];
CGRect frame = [text boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes:attributesDictionary
context:nil];
// This contains both height and width, but we really care about height.
return frame.size;
}
when the view with uitableview is refreshed (e.g. when opening and closing modalVC over it), the layout of MDHTMLLabel breaks down. I mean the alignment, both horizontal and vertical.
I use:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[cell.htmlLabel sizeToFit];
[cell setNeedsLayout];
});
to fix this, but obviously it's not the best solution and it should not happen.
EDIT: the MDHTMLLabel is inside a UITableViewCell
I'm unable to get MDHTMLLabel to work in a custom UITableViewCell. I'm trying to show a plain url, without tags. The text shows up, but it is not clickable, and the delegate is not called. I've created a small test app to demonstrate this: https://dl.dropboxusercontent.com/u/41198645/TestLabel.zip.
While trying to set html text to label, SIGABRT crash on MDHTMLLabel.m in line number 1463.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[NSCFString replaceOccurrencesOfString:withString:options:range:]: Range {0, 1} out of bounds; string length 0'
0 CoreFoundation 0x019911e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0159c8e5 objc_exception_throw + 44
2 CoreFoundation 0x01990fbb +[NSException raise:format:] + 139
3 CoreFoundation 0x0198fa44 -[__NSCFString replaceOccurrencesOfString:withString:options:range:] + 244
4 Foundation 0x01202846 -[NSString stringByReplacingOccurrencesOfString:withString:options:range:] + 218
5 InternationalAffairs 0x0000e607 -[MDHTMLLabel extractStyleFromText:] + 6359
6 InternationalAffairs 0x000049ac -[MDHTMLLabel setHtmlText:] + 428
7 InternationalAffairs 0x00016e4d -[TimeLineVC tableView:cellForRowAtIndexPath:] + 797
8 UIKit 0x0035511f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
9 UIKit 0x003551f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
10 UIKit 0x00336ece -[UITableView _updateVisibleCellsNow:] + 2428
11 UIKit 0x0034b6a5 -[UITableView layoutSubviews] + 213
12 UIKit 0x002cb964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
13 libobjc.A.dylib 0x015ae82b -[NSObject performSelector:withObject:] + 70
14 QuartzCore 0x03dfc45a -[CALayer layoutSublayers] + 148
15 QuartzCore 0x03df0244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
16 QuartzCore 0x03df00b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
17 QuartzCore 0x03d567fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
18 QuartzCore 0x03d57b85 _ZN2CA11Transaction6commitEv + 393
19 QuartzCore 0x03e24cc6 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 474
20 QuartzCore 0x03e25147 _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
21 CoreFoundation 0x0194fac6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 22
22 CoreFoundation 0x0194f4ad __CFRunLoopDoTimer + 1181
23 CoreFoundation 0x01937538 __CFRunLoopRun + 1816
24 CoreFoundation 0x019369d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x019367eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x039855ee GSEventRunModal + 192
27 GraphicsServices 0x0398542b GSEventRun + 104
28 UIKit 0x0025cf9b UIApplicationMain + 1225
29 InternationalAffairs 0x0001af1d main + 141
30 libdyld.dylib 0x01fd8701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've just updated MDHTMLLabel via cocoapods, and it seems that didSelectLinkWithURL is no longer being called?
I've set the delegate withself.htmlMessage.delegate = self;
.. I'm using MDHTMLLabel in a xib, with an IBOutlet.
great work matt
i only miss tag ;)
are you planning to add it?
It's a great component. But I found the htmlText doesn't work the same way as the text does. It seems the multiple lines is supported but the auto shrink is not supported. Do I miss something? Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.