以下大家友情支援一下:
做了一個產品,需要人氣支援一下,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