• TTTAtibutedlabel again


    NSString *contentStr = [NSString stringWithFormat:@"你和%@还是陌生人,听歌时送花给TA可以开启留言", friendInfo.nickName];
    
                    NSMutableAttributedString * tttstring = [[NSMutableAttributedStringalloc] initWithString:contentStr];
    
                    UIColor *mColor = RGBCOLOR(224, 108, 0);
    
                    [tttstring addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[mColor CGColor]range:NSMakeRange(2,friendInfo.nickName.length)];
    
                    [interactCell.strangerLb setText:tttstring];
    
     
    
    -(void)awakeFromNib
    
    {
    
        self.mTitleLabel.delegate = self;
    
    }
    
    -(void)setInfo:(CashInfo *)info
    
    {
    
        NSMutableString *mStr = [[NSMutableStringalloc]init];
    
        [mStr appendString:info.money];
    
        [mStr appendString:@"元"];
    
        NSRange mRange = [info.desc rangeOfString:mStr];
    
        NSMutableAttributedString * tttstring = [[NSMutableAttributedStringalloc] initWithString:info.desc];
    
        UIColor *mColor = RGBCOLOR(224, 108, 0);
    
        if (mRange.length != 0) {
    
            [tttstring addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[mColor CGColor] range:NSMakeRange(mRange.location, mRange.length - 1)];
    
        }
    
        NSString *sendTime = [NSDate dateStringWithTimeInterval:info.addtime];
    
        self.timeLabel.text = sendTime;
    
        [self.mTitleLabel setText:tttstring];
    
    //    self.mTitleLabel.linkAttributes = [self linkStyle];
    
    //    self.mTitleLabel.activeLinkAttributes = [self activeLinkStyle];
    
    //    [self.mTitleLabel addLinkToURL:[NSURL URLWithString:@"http://baidu.com"] withRange:NSMakeRange(2, 2)];
    
        
    
    }
    
     
    
    - (NSDictionary*)activeLinkStyle
    
    {
    
        NSMutableDictionary *mutableActiveLinkAttributes = [NSMutableDictionary dictionary];
    
        [mutableActiveLinkAttributes setValue:[NSNumber numberWithBool:NO] forKey:(NSString *)kCTUnderlineStyleAttributeName];
    
        [mutableActiveLinkAttributes setValue:(__bridge id)[[UIColor darkGrayColor] CGColor] forKey:(NSString *)kCTForegroundColorAttributeName];
    
        [mutableActiveLinkAttributes setValue:(__bridge id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f] CGColor] forKey:(NSString*)kTTTBackgroundFillColorAttributeName];
    
        [mutableActiveLinkAttributes setValue:(__bridge id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f] CGColor] forKey:(NSString*)kTTTBackgroundStrokeColorAttributeName];
    
        [mutableActiveLinkAttributes setValue:[NSNumber numberWithFloat:1.0f] forKey:(NSString *)kTTTBackgroundLineWidthAttributeName];
    
        [mutableActiveLinkAttributes setValue:[NSNumber numberWithFloat:2.0f] forKey:(NSString *)kTTTBackgroundCornerRadiusAttributeName];
    
        return mutableActiveLinkAttributes;
    
    }
    
     
    
    - (NSDictionary*)linkStyle
    
    {
    
        NSMutableDictionary *mutableActiveLinkAttributes = [NSMutableDictionary dictionary];
    
        [mutableActiveLinkAttributes setValue:[NSNumber numberWithBool:NO] forKey:(NSString *)kCTUnderlineStyleAttributeName];
    
        [mutableActiveLinkAttributes setValue:(__bridge id)[kLabelTextColor CGColor] forKey:(NSString *)kCTForegroundColorAttributeName];
    
        
    
        return mutableActiveLinkAttributes;
    
    }
    
     
    
     
    
    - (void)attributedLabel:(__unused TTTAttributedLabel *)label
    
       didSelectLinkWithURL:(NSURL *)url {
    
        [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://baidu.com"]];
    
    }
    
     
    
     [self.mTitleLabelsetText:@""afterInheritingLabelAttributesAndConfiguringWithBlock:
    
         ^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
    
            [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor redColor] range:NSMakeRange(0, 3)];
    
             return mutableAttributedString;//需要有返回值的,
    
         }];
    
     
    
                        [tttstring addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue" size:15.0] range:NSMakeRange(0, tttstring.length)];
    
    字体大小
    
     
    
    -(void)tttDiliver
    
    {
    
        [self.diliveryLabel setText:@"本商品由美月淘发货提供售后服务"afterInheritingLabelAttributesAndConfiguringWithBlock:
    
         ^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
    
             [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor blackColor] range:NSMakeRange(4, 3)];
    
            [mutableAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue" size:13.0] range:NSMakeRange(4, 3)];
    
             return mutableAttributedString;
    
         }];
    
    }
    
  • 相关阅读:
    leetcode刷题笔记 273题 整数转换英文表示
    leetcode刷题笔记 278题 第一个错误的版本
    leetcode刷题笔记 268题 丢失的数字
    leetcode刷题笔记 264题 丑数 II
    leetcode刷题笔记 263题 丑数
    20210130日报
    20210129日报
    20210128日报
    20210127日报
    20210126日报
  • 原文地址:https://www.cnblogs.com/guligei/p/9473834.html
Copyright © 2020-2023  润新知