码迷,mamicode.com
首页 > 其他好文 > 详细

TTTAtibutedlabel again

时间:2018-08-14 14:51:26      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:ber   number   nsstring   EDA   font   字体大小   key   lines   5.0   

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;

     }];

}

TTTAtibutedlabel again

标签:ber   number   nsstring   EDA   font   字体大小   key   lines   5.0   

原文地址:https://www.cnblogs.com/guligei/p/9473834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!