// 生成ctFrame
NSMutableAttributedString *attributeStringText = self.attributeStringText;
attributeStringText = [self fixLastLineMissBugWhenDrawWithCoreText:attributeStringText];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributeStringText);
-
-
Save ruandao/e7e79f5f4b01ed442356 to your computer and use it in GitHub Desktop.
core text attribute string miss last line fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (NSMutableAttributedString*)fixLastLineMissBugWhenDrawWithCoreText:(NSMutableAttributedString*)content | |
| { | |
| //段落 | |
| //line break | |
| CTParagraphStyleSetting lineBreakMode; | |
| CTLineBreakMode lineBreak = kCTLineBreakByCharWrapping; //换行模式 | |
| lineBreakMode.spec = kCTParagraphStyleSpecifierLineBreakMode; | |
| lineBreakMode.value = &lineBreak; | |
| lineBreakMode.valueSize = sizeof(CTLineBreakMode); | |
| //行间距 | |
| CTParagraphStyleSetting LineSpacing; | |
| CGFloat spacing = 0.0; //指定间距 | |
| LineSpacing.spec = kCTParagraphStyleSpecifierLineSpacingAdjustment; | |
| LineSpacing.value = &spacing; | |
| LineSpacing.valueSize = sizeof(CGFloat); | |
| CTParagraphStyleSetting settings[] = {lineBreakMode,LineSpacing}; | |
| CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, 2); //第二个参数为settings的长度 | |
| [content addAttribute:(NSString *)kCTParagraphStyleAttributeName | |
| value:(__bridge id)paragraphStyle | |
| range:NSMakeRange(0, content.length)]; | |
| CFRelease(paragraphStyle); | |
| return content; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment