欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

iOS删除线和下划线

程序员文章站 2022-03-09 09:29:36
...
@interface NSString (line)
//删除线
-(NSMutableAttributedString *)addPartionLineStr:(NSString *)str;
//下划线
-(NSMutableAttributedString *)addUnderLineStr:(NSString *)str;

@end


@implementation NSString (line)
//删除线
-(NSMutableAttributedString *)addPartionLineStr:(NSString *)str{
    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:self
                                                                                attributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleNone)}];
    [attrStr setAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),
                             NSBaselineOffsetAttributeName : @0} range:[self rangeOfString:str]];
    return attrStr;
}
//下划线
-(NSMutableAttributedString *)addUnderLineStr:(NSString *)str{
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str
                                                                                attributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleNone)}];
    [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:[self rangeOfString:str]];
    return attrStr;
}

@end


相关标签: 删除线 下划线