How does iPhone IOS display different fonts and color texts (uilabel) in the same line)

Source: Internet
Author: User

The following are some of your friendly support:

Made a product, need popularity support a bit, Android and iPhone 91 market search # super junior mission #, or directly to the page to download the http://m.ixingji.com/m.html? P = x16. You can join us.

The same line of text can display different fonts, bold, italic, and color texts, and feedback click events.

Inherited from uilabel

1. From open-source tttattributedlabel

Https://github.com/mattt/TTTAttributedLabel

2. This involves a concept nsmutableattributedstring. It seems to be mainly used for conversion in HTML and text. For specific usage, see the following code.

3. How to use:

#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];

See

4. Recommended articles

How to make IOS and Android support custom Fonts

Http://icyleaf.com/2011/07/06/custom-fonts-both-in-ios-and-android/

Uilabel of the Custom font

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.