以下大家友情支持一下:
做了一个产品,需要人气支持一下,android和iphone上91市场搜索#super junior粉丝团#,或者直接到页面下载http://m.ixingji.com/m.html?p=X16,大家帮忙捧捧场。
同一行文字可以显示不同的字体,加粗,斜体,颜色的文本,同时还能反馈点击事件。
继承自UILabel
1。来自开源代码TTTAttributedLabel
https://github.com/mattt/TTTAttributedLabel
2。涉及到一个概念NSMutableAttributedString, 这个东西好像主要用在html和文本见转换用,具体用法见下面的代码
3。如何使用:
#import "TTTAttributedLabel.h" #import <UIKit/UIKit.h> #import <CoreText/CoreText.h> self.summaryLabel = [[[TTTAttributedLabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease]; self.summaryLabel.font = [UIFont systemFontOfSize:kSummaryTextFontSize]; self.summaryLabel.textColor = [UIColor blackColor]; self.summaryLabel.lineBreakMode = UILineBreakModeWordWrap; self.summaryLabel.numberOfLines = 0; self.summaryLabel.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCTUnderlineStyleAttributeName]; self.summaryLabel.highlightedTextColor = [UIColor redColor]; self.summaryLabel.shadowColor = [UIColor colorWithWhite:0.87 alpha:1.0]; self.summaryLabel.shadowOffset = CGSizeMake(0.0f, 1.0f); self.summaryLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop; NSMutableAttributedString * tttstring = [[NSMutableAttributedString alloc] initWithString:@"firstsecondthird"]; UIFont *italicSystemFont = [UIFont italicSystemFontOfSize:kSummaryTextFontSize]; CTFontRef italicFont = CTFontCreateWithName((CFStringRef)italicSystemFont.fontName, italicSystemFont.pointSize, NULL); if(italicFont){ [tttstring addAttribute:(NSString *)kCTFontAttributeName value:(id)italicFont range:NSMakeRange(5,6)]; } CFRelease(italicFont); [tttstring addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor redColor] CGColor] range:NSMakeRange(0,5)]; [self.summaryLabel setText:tttstring];
4.推荐文章
如何让 iOS 和 Android 支持自定义字体
http://icyleaf.com/2011/07/06/custom-fonts-both-in-ios-and-android/
自定义字体的UILabel
http://pimacun.72pines.com/2011/05/09/%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AD%97%E4%BD%93%E7%9A%84uilabel/
http://blog.csdn.net/microchenhong/article/details/6542994