NSAttributedString富文本

typedef NS_ENUM(NSInteger, FRNoteStepsType) {//B加粗  I倾斜  U下划线  S中间横线

    FRNoteStepsTypeTextNormal=3030,//Note页输入字体无状态

    FRNoteStepsTypeTextBold,//Note页输入字体加粗

    FRNoteStepsTypeTextTilt,//Note页输入字体倾斜

    FRNoteStepsTypeTextTiltUnderLine,//Note页输入字体添加下划线

    FRNoteStepsTypeTextTiltHorizontalLine,//Note页输入字体添加中间横线

    FRNoteStepsTypeTextBI,//加粗+倾斜

    FRNoteStepsTypeTextBU,//加粗+下划线

    FRNoteStepsTypeTextBS,//加粗+中间横线

    FRNoteStepsTypeTextIU,//倾斜+下划线

    FRNoteStepsTypeTextIS,//倾斜+中间横线

    FRNoteStepsTypeTextUS,//下划线+中间横线

    FRNoteStepsTypeTextBIU,//加粗+倾斜+下划线

    FRNoteStepsTypeTextBIS,//加粗+倾斜+中间横线

    FRNoteStepsTypeTextBUS,//加粗+下划线+中间横线

    FRNoteStepsTypeTextIUS,//倾斜+下划线+中间横线

    FRNoteStepsTypeTextBIUS,//加粗+倾斜+下划线+中间横线

};



//设置新的富文本内容

+ (NSAttributedString*)getNewsAttribute:(NSString*)inputTexttextAttribute:(FRNoteStepsType)textAttribute textColor:(UIColor*)textColor{


    UIColor*attColor = textColor ? textColor :kBaseModel.cellTitleColor;


    switch(textAttribute) {

        case FRNoteStepsTypeTextNormal://Note页输入字体无状态

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_SystemFont(16),NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBold://Note页输入字体加粗

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextTilt://Note页输入字体倾斜

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName :FR_SystemFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextTiltUnderLine://Note页输入字体添加下划线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName :FR_SystemFont(16),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextTiltHorizontalLine://Note页输入字体添加中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName :FR_SystemFont(16),NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;


        case FRNoteStepsTypeTextBI://加粗+倾斜

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBU://加粗+下划线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBS://加粗+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBIU://加粗+倾斜+下划线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBIS://加粗+倾斜+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBUS://加粗+下划线+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextBIUS://加粗+倾斜+下划线+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_MediumFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextIU://倾斜+下划线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName :FR_SystemFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextIS://倾斜+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_SystemFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextIUS://倾斜+下划线+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName : FR_SystemFont(16),NSObliquenessAttributeName : @(0.5),NSExpansionAttributeName : @(0),NSVerticalGlyphFormAttributeName : @(0),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;

        case FRNoteStepsTypeTextUS://下划线+中间横线

        {

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:inputText attributes:@{NSForegroundColorAttributeName:attColor,NSFontAttributeName :FR_SystemFont(16),NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),NSUnderlineColorAttributeName : attColor,NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName : attColor,NSKernAttributeName :@(1)}];

            returnattributeStr;

        }

            break;


        default:

            break;

    }

    return [[NSAttributedString alloc]initWithString:inputText];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容