Latest 0.3.0
Homepage https://github.com/xuliang2015/XAttributedString
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

XAttributedString is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'XAttributedString'

Usage

// 设置属性字符
NSString *text = @"测试属性字符";
NSMutableAttributedString *mAtrStr = [[NSMutableAttributedString alloc] initWithString:text];
[mAtrStr x_addAttributeTextColor:[UIColor redColor] range:NSMakeRange(2, 2)];
[mAtrStr x_addAttributeFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 2)];
[mAtrStr x_addAttributeUnderlineStyle:NSUnderlineStyleSingle color:[UIColor blackColor] range:NSMakeRange(4, 2)];
[self.atrLab setAttributedText:mAtrStr];

// 设置属性字符
NSString *text2 = @"测试可点击字符";
NSMutableAttributedString *mAtrStr2 = [[NSMutableAttributedString alloc] initWithString:text2];
// 若点击位置不准确,可能通过以下方案解决,详情查看接口说明
[self.atrTapLab x_setDefaultFont:self.atrTapLab.font];
[mAtrStr2 x_addAttributeTextColor:[UIColor redColor] range:NSMakeRange(2, 3)];
[mAtrStr2 x_addAttributeFont:[UIFont systemFontOfSize:40] range:NSMakeRange(0, 1)];
[self.atrTapLab setAttributedText:mAtrStr2];

// 设置可点击区域
[self.atrTapLab x_addTapEvent:^(NSUInteger index, NSAttributedString * _Nullable attrStr) {
    NSLog(@"====== index: %ld, str: %@", index, attrStr);
} range:NSMakeRange(2, 3)];

Author

xuliang, [email protected]

License

XAttributedString is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "XAttributedString",
    "version": "0.3.0",
    "summary": "A short description of XAttributedString.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/xuliang2015/XAttributedString",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "xuliang": "[email protected]"
    },
    "source": {
        "git": "https://github.com/xuliang2015/XAttributedString.git",
        "tag": "0.3.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "XAttributedString/Classes/**/*"
}

Pin It on Pinterest

Share This