NSMutableAttributedString属性文字

//
//  ViewController.m
//  NSMutableAttributedString
//
//  Created by zhengbing on 6/30/16.
//  Copyright © 2016 zhengbing. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *str = @"1234567";
    NSMutableAttributedString *astr = [[NSMutableAttributedString alloc] initWithString:str];
    [astr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
    [astr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(3, 2)];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100,100)];
    label.attributedText = astr;

    [self.view addSubview:label];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

你可能感兴趣的:(Objective-C,基础知识)