Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added warnings for known unsupported/ignored properties (adjustFontSi…

…zeToFit, etc) not handled by CoreText
  • Loading branch information...
commit 08ede9a8bc387c438600a6a35d0afe6bc2ce6e96 1 parent b8c681a
@AliSoftware authored
View
2  AttributedLabel Example/Classes/AttributedLabel_ExampleAppDelegate.m
@@ -50,7 +50,7 @@ - (void)applicationWillTerminate:(UIApplication *)application {
#define TXT_END " with your friends!"
-(IBAction)fillLabel1 {
- NSString* txt = @ TXT_BEGIN TXT_BOLD TXT_MIDDLE TXT_LINK TXT_END; // concat the 3 (#define) constant parts in a single NSString
+ NSString* txt = @ TXT_BEGIN TXT_BOLD TXT_MIDDLE TXT_LINK TXT_END; // concat the 5 (#define) constant parts in a single NSString
/**(1)** Build the NSAttributedString *******/
NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:txt];
// for those calls we don't specify a range so it affects the whole string
View
1  AttributedLabel Example/MainWindow.xib
@@ -74,6 +74,7 @@
<bytes key="NSWhite">MQA</bytes>
</object>
<int key="IBUIBaselineAdjustment">1</int>
+ <bool key="IBUIAdjustsFontSizeToFit">NO</bool>
<float key="IBUIMinimumFontSize">10</float>
<int key="IBUINumberOfLines">4</int>
<int key="IBUILineBreakMode">0</int>
View
57 OHAttributedLabel.m
@@ -144,6 +144,10 @@ -(NSTextCheckingResult*)linkAtPoint:(CGPoint)pt;
-(NSMutableAttributedString*)attributedTextWithLinks;
-(void)resetTextFrame;
-(void)drawActiveLinkHighlightForRect:(CGRect)rect;
+#if OHAttributedLabel_WarnAboutKnownIssues
+-(void)warnAboutKnownIssues_CheckLineBreakMode;
+-(void)warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth;
+#endif
@end
@@ -194,6 +198,10 @@ - (id)initWithCoder:(NSCoder *)decoder
self = [super initWithCoder:decoder];
if (self != nil) {
[self commonInit];
+#if OHAttributedLabel_WarnAboutKnownIssues
+ [self warnAboutKnownIssues_CheckLineBreakMode];
+ [self warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth];
+#endif
}
return self;
}
@@ -580,20 +588,12 @@ -(void)setLineBreakMode:(UILineBreakMode)lineBreakMode {
CTTextAlignment coreTextAlign = CTTextAlignmentFromUITextAlignment(self.textAlignment);
CTLineBreakMode coreTextLBMode = CTLineBreakModeFromUILineBreakMode(lineBreakMode);
[_attributedText setTextAlignment:coreTextAlign lineBreakMode:coreTextLBMode];
-
-#if OHAttributedLabel_WarnAboutKnownIssues
- BOOL truncationMode = (lineBreakMode == UILineBreakModeHeadTruncation)
- | (lineBreakMode == UILineBreakModeMiddleTruncation)
- | (lineBreakMode == UILineBreakModeTailTruncation);
- if (truncationMode && self.numberOfLines > 1) {
- NSLog(@"[OHAttributedLabel] Warning: \"UILineBreakMode...Truncation\" lineBreakModes not yet fully supported by CoreText and OHAttributedLabel"
- " (truncation will appear on first line, ignoring the rest of the text)");
- NSLog(@" This is a known issue (Help to solve is would be greatly appreciated).");
- NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/3");
- }
-#endif
[super setLineBreakMode:lineBreakMode]; // will call setNeedsDisplay too
+
+#if OHAttributedLabel_WarnAboutKnownIssues
+ [self warnAboutKnownIssues_CheckLineBreakMode];
+#endif
}
-(void)setCenterVertically:(BOOL)val {
centerVertically = val;
@@ -623,23 +623,32 @@ -(void)setNeedsDisplay {
/////////////////////////////////////////////////////////////////////////////
#if OHAttributedLabel_WarnAboutKnownIssues
--(void)setAdjustsFontSizeToFitWidth:(BOOL)value {
- if (value) {
- NSLog(@"[OHAttributedLabel] Warning: \"adjustsFontSizeToFitWidth\" property not supported by CoreText and OHAttributedLabel! This property will be ignored.");
- }
- [super setAdjustsFontSizeToFitWidth:value];
-}
-
--(void)setNumberOfLines:(NSInteger)nbLines {
+-(void)warnAboutKnownIssues_CheckLineBreakMode {
BOOL truncationMode = (self.lineBreakMode == UILineBreakModeHeadTruncation)
| (self.lineBreakMode == UILineBreakModeMiddleTruncation)
| (self.lineBreakMode == UILineBreakModeTailTruncation);
@a2
a2 added a note

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 Owner

Totally right, nice catch ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- if (truncationMode && nbLines > 1) {
- NSLog(@"[OHAttributedLabel] Warning: the numberOfLines property is not yet supported by CoreText and OHAttributedLabel."
- " (this property is ignored right now)");
+ if (truncationMode) {
+ NSLog(@"[OHAttributedLabel] Warning: \"UILineBreakMode...Truncation\" lineBreakModes not yet fully supported by CoreText and OHAttributedLabel");
+ NSLog(@" (truncation will appear on each paragraph instead of the whole text)");
NSLog(@" This is a known issue (Help to solve is would be greatly appreciated).");
- NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/34");
+ NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/3");
+ }
+}
+-(void)warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth {
+ if (self.adjustsFontSizeToFitWidth) {
+ NSLog(@"[OHAttributedLabel] Warning: \"adjustsFontSizeToFitWidth\" property not supported by CoreText and OHAttributedLabel! This property will be ignored.");
}
+}
+-(void)setAdjustsFontSizeToFitWidth:(BOOL)value {
+ [super setAdjustsFontSizeToFitWidth:value];
+ [self warnAboutKnownIssues_CheckAdjustsFontSizeToFitWidth];
+}
+
+-(void)setNumberOfLines:(NSInteger)nbLines {
+ NSLog(@"[OHAttributedLabel] Warning: the numberOfLines property is not yet supported by CoreText and OHAttributedLabel. (this property is ignored right now)");
+ NSLog(@" This is a known issue (Help to solve is would be greatly appreciated).");
+ NSLog(@" See https://github.com/AliSoftware/OHAttributedLabel/issues/34");
+
[super setNumberOfLines:nbLines];
}
#endif
@a2

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.