NSMutableAttributeString
来源:互联网 发布:oracle sql nvl函数 编辑:程序博客网 时间:2024/06/08 00:07
[mutableAttributed addAttribute:(NSString *)(kCTForegroundColorAttributeName)
value:(id)[UIColor blueColor].CGColor
range:NSMakeRange(0, len)];
CTFontRef ctFont = CTFontCreateWithName((CFStringRef)AtFont.fontName,
AtFont.pointSize,
NULL);
[mutableAttributed addAttribute:(NSString *)(kCTFontAttributeName)
value:(id)ctFont
range:NSMakeRange(0, 1)];
[attrString addAttribute:(__bridge NSString *)(kCTForegroundColorAttributeName)
value:(id)[UIColor blueColor].CGColor
range:NSMakeRange(0, len)];
[mutableAttributed addAttribute:(__bridge NSString*)kCTUnderlineStyleAttributeName value:[NSNumbernumberWithInteger:NSSingleUnderlineStyle] range:range];
@property (nonatomic, assign) CGFloat lineSpacing;
/* Distance between the bottom of this paragraph and top of next (or the beginning of its paragraphSpacingBefore, if any) */
@property (nonatomic, assign) CGFloat paragraphSpacing;
@property (nonatomic, assign) CTTextAlignment textAlignment;
@property (nonatomic, assign) CTLineBreakMode lineBreakMode;
@property (nonatomic, assign) CGFloat firstLineHeadIndent; // Distance from margin to edge appropriate for text direction
@property (nonatomic, assign) CGFloat headIndent; // Distance from margin to front edge of paragraph
@property (nonatomic, assign) CGFloat tailIndent; // Distance from margin to back edge of paragraph. Use negative values for distance to other edge.
@property (nonatomic, assign) CGFloat minimumLineHeight;
@property (nonatomic, assign) CGFloat maximumLineHeight; // 0 implies no maximum.
/* Natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. */
@property (nonatomic, assign) CGFloat lineHeightMultiple;
/* Distance between the bottom of the previous paragraph (or the end of its paragraphSpacing, if any) and the top of this paragraph. */
@property (nonatomic, assign) CGFloat paragraphSpacingBefore;
+(CTParagraphStyleRef)createCTParagraphStyle (添加类别)
{
const int kSettingsCount = 12;
CTParagraphStyleSetting settings[kSettingsCount] =
{
{ kCTParagraphStyleSpecifierLineSpacing, sizeof(_lineSpacing), &_lineSpacing },
{ kCTParagraphStyleSpecifierParagraphSpacing, sizeof(_paragraphSpacing), &_paragraphSpacing },
{ kCTParagraphStyleSpecifierAlignment, sizeof(_textAlignment), &_textAlignment },
{ kCTParagraphStyleSpecifierLineBreakMode, sizeof(_lineBreakMode), &_lineBreakMode },
{ kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(_firstLineHeadIndent), &_firstLineHeadIndent},
{ kCTParagraphStyleSpecifierHeadIndent, sizeof(_headIndent), &_headIndent},
{ kCTParagraphStyleSpecifierTailIndent, sizeof(_tailIndent), &_tailIndent},
{ kCTParagraphStyleSpecifierBaseWritingDirection, sizeof(_baseWritingDirection), &_baseWritingDirection },
{ kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(_minimumLineHeight), &_minimumLineHeight },
{ kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(_maximumLineHeight), &_maximumLineHeight },
{ kCTParagraphStyleSpecifierLineHeightMultiple, sizeof(_lineHeightMultiple), &_lineHeightMultiple },
{ kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(_paragraphSpacingBefore), &_paragraphSpacingBefore }
};
return CTParagraphStyleCreate(settings, kSettingsCount);
}
CTParagraphStyleRef newParaStyle = [CTParagraphStyleRef createCTParagraphStyle];
[self removeAttribute:(__bridge NSString*)kCTParagraphStyleAttributeName range:range]; // Work around for Apple leak
[self addAttribute:(__bridge NSString*)kCTParagraphStyleAttributeName value:(__bridge id)newParaStyle range:range];
CFRelease(newParaStyle);
iOS6 以上(包括IOS6)
NSMutableParagraphStyle *paragraphStyle;
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSCenterTextAlignment];
NSFont *displayFont = [NSFont fontWithName:@"Helvetica-BoldOblique" size:18];
NSDictionary *attribDict = [NSDictionary dictionaryWithObjectsAndKeys:displayFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil];
NSAttributedString *attrib = [[NSAttributedString alloc] initWithString:@"hello, world" attributes:attribDict];
[displayField setAttributedTitle:attrib];
[attrib release];
[paragraphStyle release];
value:(id)[UIColor blueColor].CGColor
range:NSMakeRange(0, len)];
CTFontRef ctFont = CTFontCreateWithName((CFStringRef)AtFont.fontName,
AtFont.pointSize,
NULL);
[mutableAttributed addAttribute:(NSString *)(kCTFontAttributeName)
value:(id)ctFont
range:NSMakeRange(0, 1)];
[attrString addAttribute:(__bridge NSString *)(kCTForegroundColorAttributeName)
value:(id)[UIColor blueColor].CGColor
range:NSMakeRange(0, len)];
[mutableAttributed addAttribute:(__bridge NSString*)kCTUnderlineStyleAttributeName value:[NSNumbernumberWithInteger:NSSingleUnderlineStyle] range:range];
////////////////////////////////////////////////////////////////////////////////////////////
@property (nonatomic, assign) CGFloat lineSpacing;
/* Distance between the bottom of this paragraph and top of next (or the beginning of its paragraphSpacingBefore, if any) */
@property (nonatomic, assign) CGFloat paragraphSpacing;
@property (nonatomic, assign) CTTextAlignment textAlignment;
@property (nonatomic, assign) CTLineBreakMode lineBreakMode;
@property (nonatomic, assign) CGFloat firstLineHeadIndent; // Distance from margin to edge appropriate for text direction
@property (nonatomic, assign) CGFloat headIndent; // Distance from margin to front edge of paragraph
@property (nonatomic, assign) CGFloat tailIndent; // Distance from margin to back edge of paragraph. Use negative values for distance to other edge.
@property (nonatomic, assign) CTWritingDirection baseWritingDirection;
@property (nonatomic, assign) CGFloat minimumLineHeight;
@property (nonatomic, assign) CGFloat maximumLineHeight; // 0 implies no maximum.
/* Natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. */
@property (nonatomic, assign) CGFloat lineHeightMultiple;
/* Distance between the bottom of the previous paragraph (or the end of its paragraphSpacing, if any) and the top of this paragraph. */
@property (nonatomic, assign) CGFloat paragraphSpacingBefore;
+(CTParagraphStyleRef)createCTParagraphStyle (添加类别)
{
const int kSettingsCount = 12;
CTParagraphStyleSetting settings[kSettingsCount] =
{
{ kCTParagraphStyleSpecifierLineSpacing, sizeof(_lineSpacing), &_lineSpacing },
{ kCTParagraphStyleSpecifierParagraphSpacing, sizeof(_paragraphSpacing), &_paragraphSpacing },
{ kCTParagraphStyleSpecifierAlignment, sizeof(_textAlignment), &_textAlignment },
{ kCTParagraphStyleSpecifierLineBreakMode, sizeof(_lineBreakMode), &_lineBreakMode },
{ kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(_firstLineHeadIndent), &_firstLineHeadIndent},
{ kCTParagraphStyleSpecifierHeadIndent, sizeof(_headIndent), &_headIndent},
{ kCTParagraphStyleSpecifierTailIndent, sizeof(_tailIndent), &_tailIndent},
{ kCTParagraphStyleSpecifierBaseWritingDirection, sizeof(_baseWritingDirection), &_baseWritingDirection },
{ kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(_minimumLineHeight), &_minimumLineHeight },
{ kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(_maximumLineHeight), &_maximumLineHeight },
{ kCTParagraphStyleSpecifierLineHeightMultiple, sizeof(_lineHeightMultiple), &_lineHeightMultiple },
{ kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(_paragraphSpacingBefore), &_paragraphSpacingBefore }
};
return CTParagraphStyleCreate(settings, kSettingsCount);
}
CTParagraphStyleRef newParaStyle = [CTParagraphStyleRef createCTParagraphStyle];
[self removeAttribute:(__bridge NSString*)kCTParagraphStyleAttributeName range:range]; // Work around for Apple leak
[self addAttribute:(__bridge NSString*)kCTParagraphStyleAttributeName value:(__bridge id)newParaStyle range:range];
CFRelease(newParaStyle);
iOS6 以上(包括IOS6)
NSMutableParagraphStyle *paragraphStyle;
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSCenterTextAlignment];
NSFont *displayFont = [NSFont fontWithName:@"Helvetica-BoldOblique" size:18];
NSDictionary *attribDict = [NSDictionary dictionaryWithObjectsAndKeys:displayFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil];
NSAttributedString *attrib = [[NSAttributedString alloc] initWithString:@"hello, world" attributes:attribDict];
[displayField setAttributedTitle:attrib];
[attrib release];
[paragraphStyle release];
0 0
- NSMutableAttributeString
- NSAttributeString和NSMutableAttributeString
- iOS开发笔记之NSMutableAttributeString富文本
- Swift3:NSMutableAttributeString的Range和NSRange问题
- [绍棠_Swift] swift4.0 NSMutableAttributeString的Range和NSRange问题
- 一个GRIDVIEW控件如何绑定两张不同的表
- dos命令及java简介
- Java多线程与并发库高级应用之倒计时计数器CountDownLatch
- pedump.c
- Web自动化测试(3): Selenium Web Driver 如何操作web页面。
- NSMutableAttributeString
- TranslateAnimation详解
- Eclipse快捷键 10个最有用的快捷键
- Builder 模式
- 关于Jpcap的配置问题
- 服务器负载均衡的部署方式
- 直接运行内存中的程序
- 间隔分区
- 腾讯2011.10.15校园招聘会笔试题