Objective-C属性字符串NSAttributedString

NSAttributedString是Objective-C中的属性字符串类,GitHub上也有很多第三方,用得较多的是TTTAttributedLabel,这里给大家介绍一下系统NSAttributedString类来实现富文本,并可实现点击事件,同时点击事件可携带参数。
因为要做点击事件,所以我们用UITextView,首先声明一个UITextView属性:

@property (nonatomic, strong) UITextView *textView;

NSAttributedString中NSFontAttributeName是用来设置文字字体的,有很多可以设置的属性,这里介绍一些常用的,其他的用到的话修改一下key-value就可以了:

//NSFontAttributeName:文字字体
- (void)setAttributeCorlorAndSize{
    _textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH, 100)];
    _textView.editable = NO;
    _textView.selectable = NO;
    _textView.scrollEnabled = NO;
    _textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:_textView];

    //初始化属性字符串
    NSMutableAttributedString * aAttributedString =

你可能感兴趣的:(iOS开发,iOS开发入门到精通,objective-c,NSAttribut,属性字符串)