您的位置:首页 > 移动开发 > IOS开发

NSMutableAttributedString属性文字

2016-06-30 16:53 288 查看
//
//  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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS-属性文字