Skip to content
This repository
Browse code

Added warnings for known unsupported/ignored properties (adjustFontSi…

…zeToFit, etc) not handled by CoreText
  • Loading branch information...
commit 08ede9a8bc387c438600a6a35d0afe6bc2ce6e96 1 parent b8c681a
AliSoftware authored
2  AttributedLabel Example/Classes/AttributedLabel_ExampleAppDelegate.m
@@ -50,7 +50,7 @@ - (void)applicationWillTerminate:(UIApplication *)application {
50 50 #define TXT_END " with your friends!"
51 51
52 52 -(IBAction)fillLabel1 {
53   - NSString* txt = @ TXT_BEGIN TXT_BOLD TXT_MIDDLE TXT_LINK TXT_END; // concat the 3 (#define) constant parts in a single NSString
  53 + NSString* txt = @ TXT_BEGIN TXT_BOLD TXT_MIDDLE TXT_LINK TXT_END; // concat the 5 (#define) constant parts in a single NSString
54 54 /**(1)** Build the NSAttributedString *******/
55 55 NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:txt];
56 56 // for those calls we don't specify a range so it affects the whole string
1  AttributedLabel Example/MainWindow.xib
@@ -74,6 +74,7 @@
74 74 <bytes key="NSWhite">MQA</bytes>
75 75 </object>
76 76 <int key="IBUIBaselineAdjustment">1</int>
  77 + <bool key="IBUIAdjustsFontSizeToFit">NO</bool>
77 78 <float key="IBUIMinimumFontSize">10</float>
78 79 <int key="IBUINumberOfLines">4</int>
79 80 <int key="IBUILineBreakMode">0</int>
57 OHAttributedLabel.m
@@ -144,6 +144,10 @@ -(NSTextCheckingResult*)linkAtPoint:(CGPoint)pt;
144 144 -(NSMutableAttributedString*)attributedTextWithLinks;
145 145 -(void)resetTextFrame;
146 146 -(void)drawActiveLinkHighlightForRect:(CGRect)rect;
  147 +#if OHAttributedLabel_WarnAboutKnownIssues
  148 +-(void)warnAboutKnownIssues_CheckLineBreakMode;
  149 +-(void)warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth;
  150 +#endif
147 151 @end
148 152
149 153
@@ -194,6 +198,10 @@ - (id)initWithCoder:(NSCoder *)decoder
194 198 self = [super initWithCoder:decoder];
195 199 if (self != nil) {
196 200 [self commonInit];
  201 +#if OHAttributedLabel_WarnAboutKnownIssues
  202 + [self warnAboutKnownIssues_CheckLineBreakMode];
  203 + [self warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth];
  204 +#endif
197 205 }
198 206 return self;
199 207 }
@@ -580,20 +588,12 @@ -(void)setLineBreakMode:(UILineBreakMode)lineBreakMode {
580 588 CTTextAlignment coreTextAlign = CTTextAlignmentFromUITextAlignment(self.textAlignment);
581 589 CTLineBreakMode coreTextLBMode = CTLineBreakModeFromUILineBreakMode(lineBreakMode);
582 590 [_attributedText setTextAlignment:coreTextAlign lineBreakMode:coreTextLBMode];
583   -
584   -#if OHAttributedLabel_WarnAboutKnownIssues
585   - BOOL truncationMode = (lineBreakMode == UILineBreakModeHeadTruncation)
586   - | (lineBreakMode == UILineBreakModeMiddleTruncation)
587   - | (lineBreakMode == UILineBreakModeTailTruncation);
588   - if (truncationMode && self.numberOfLines > 1) {
589   - NSLog(@"[OHAttributedLabel] Warning: \"UILineBreakMode...Truncation\" lineBreakModes not yet fully supported by CoreText and OHAttributedLabel"
590   - " (truncation will appear on first line, ignoring the rest of the text)");
591   - NSLog(@" This is a known issue (Help to solve is would be greatly appreciated).");
592   - NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/3");
593   - }
594   -#endif
595 591
596 592 [super setLineBreakMode:lineBreakMode]; // will call setNeedsDisplay too
  593 +
  594 +#if OHAttributedLabel_WarnAboutKnownIssues
  595 + [self warnAboutKnownIssues_CheckLineBreakMode];
  596 +#endif
597 597 }
598 598 -(void)setCenterVertically:(BOOL)val {
599 599 centerVertically = val;
@@ -623,23 +623,32 @@ -(void)setNeedsDisplay {
623 623 /////////////////////////////////////////////////////////////////////////////
624 624
625 625 #if OHAttributedLabel_WarnAboutKnownIssues
626   --(void)setAdjustsFontSizeToFitWidth:(BOOL)value {
627   - if (value) {
628   - NSLog(@"[OHAttributedLabel] Warning: \"adjustsFontSizeToFitWidth\" property not supported by CoreText and OHAttributedLabel! This property will be ignored.");
629   - }
630   - [super setAdjustsFontSizeToFitWidth:value];
631   -}
632   -
633   --(void)setNumberOfLines:(NSInteger)nbLines {
  626 +-(void)warnAboutKnownIssues_CheckLineBreakMode {
634 627 BOOL truncationMode = (self.lineBreakMode == UILineBreakModeHeadTruncation)
635 628 | (self.lineBreakMode == UILineBreakModeMiddleTruncation)
636 629 | (self.lineBreakMode == UILineBreakModeTailTruncation);
637   - if (truncationMode && nbLines > 1) {
638   - NSLog(@"[OHAttributedLabel] Warning: the numberOfLines property is not yet supported by CoreText and OHAttributedLabel."
639   - " (this property is ignored right now)");
  630 + if (truncationMode) {
  631 + NSLog(@"[OHAttributedLabel] Warning: \"UILineBreakMode...Truncation\" lineBreakModes not yet fully supported by CoreText and OHAttributedLabel");
  632 + NSLog(@" (truncation will appear on each paragraph instead of the whole text)");
640 633 NSLog(@" This is a known issue (Help to solve is would be greatly appreciated).");
641   - NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/34");
  634 + NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/3");
  635 + }
  636 +}
  637 +-(void)warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth {
  638 + if (self.adjustsFontSizeToFitWidth) {
  639 + NSLog(@"[OHAttributedLabel] Warning: \"adjustsFontSizeToFitWidth\" property not supported by CoreText and OHAttributedLabel! This property will be ignored.");
642 640 }
  641 +}
  642 +-(void)setAdjustsFontSizeToFitWidth:(BOOL)value {
  643 + [super setAdjustsFontSizeToFitWidth:value];
  644 + [self warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth];
  645 +}
  646 +
  647 +-(void)setNumberOfLines:(NSInteger)nbLines {
  648 + NSLog(@"[OHAttributedLabel] Warning: the numberOfLines property is not yet supported by CoreText and OHAttributedLabel. (this property is ignored right now)");
  649 + NSLog(@" This is a known issue (Help to solve is would be greatly appreciated).");
  650 + NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/34");
  651 +
643 652 [super setNumberOfLines:nbLines];
644 653 }
645 654 #endif

0 comments on commit 08ede9a

Alexsander Akers

You probably want to make the bitwise ORs into Boolean ORs. Not that it matters in this particular instance, but just as a general coding habit.

AliSoftware

Totally right, nice catch ;)

Please sign in to comment.
Something went wrong with that request. Please try again.