tobihagemann / THLabel

UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.
https://tobiha.de
Other
665 stars 111 forks source link

Crash when setStrokeColor is null in iOS 7 #4

Closed kokeshi92 closed 10 years ago

kokeshi92 commented 11 years ago

Hi , there. I use this great open source. thank you.

By the way ,I encountered crash bug recently.

my code THLabel albumButtonLabel = [[THLabel alloc] initWithFrame:CGRectMake(albumButton.frame.origin.x - 10, albumButton.frame.origin.y + albumButton.frame.size.height - 15, 170, 33)]; albumButtonLabel.text = NSLocalizedString(@"START_BUTTON_ALBUM", nil); albumButtonLabel.font = [UIFont fontWithName:@"mikachan_o-PB" size:16]; albumButtonLabel.backgroundColor = [UIColor clearColor]; albumButtonLabel.textColor = [UIColor whiteColor]; albumButtonLabel.shadowBlur = 3.0f; albumButtonLabel.shadowColor = [UIColor grayColor]; albumButtonLabel.shadowOffset = CGSizeMake(2.0f, 2.0f); albumButtonLabel.transform = CGAffineTransformMakeRotation(18.0f \ M_PI/180);

In iOS6 , there is no problem without setting strokeColor , but in iOS7 crashed.

crash at // ------- // Step 4: Draw stroke. // ------- if ([self.text respondsToSelector:@selector(sizeWithAttributes:)]) {//colorがnullの時 NSDictionary attrs = @{NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle, NSStrokeColorAttributeName: self.color NSStrokeWidthAttributeName: @([self strokeSizeDependentOnStrokePosition] \ [UIScreen mainScreen].scale)};

[self drawTextInRect:textRect withAttributes:attrs]; 

}

crash log * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'

So , I add following code before "NSDictionary *attrs = @{......" id color = self.strokeColor; if(!color){ color = [NSNull null]; }

My test enviroment [iPhone Retina(4-inch , 64bit) iOS 7.0]. [iPhone Retina(4-inch ) iOS 7.0]. [iPhone4 iOS7.0 GM Seed].

Sorry my poor English. Thank in advance.

tobihagemann commented 11 years ago

Hi, have you tried updating to THLabel version 1.1? Don't forget to add CoreText.framework. I've moved away from drawing with attributes on iOS 7, it was a bad approach from me. I'll look into it, if you're still experiencing crashes after updating to 1.1! :)