• TTTAttributedLabel颜色设置


        NSString *text = @"Lorem ipsum dolor sit amet";
        [self.testAttributedLabel setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
            NSRange boldRange = [[mutableAttributedString string] rangeOfString:@"ipsum dolor" options:NSCaseInsensitiveSearch];
            NSRange strikeRange = [[mutableAttributedString string] rangeOfString:@"sit amet" options:NSCaseInsensitiveSearch];
            
            // Core Text APIs use C functions without a direct bridge to UIFont. See Apple's "Core Text Programming Guide" to learn how to configure string attributes.
            UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:14];
            CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
            if (font) {
                [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:boldRange];
                [mutableAttributedString addAttribute:kTTTStrikeOutAttributeName value:@YES range:strikeRange];
                CFRelease(font);
            }
            //TTTAttributedLabel颜色设置
            [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor blueColor] CGColor] range:boldRange];
    //        [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:[UIColor blueColor] range:boldRange];
            
            return mutableAttributedString;
        }];
    

      

  • 相关阅读:
    辣条君写爬虫1【贝壳房价爬取】
    如何在 Windows 上创建一个新的 GPG key
    Protocol Buffers 开发者指南
    Docsify 的边栏目录如何设置
    Docker 容器的网络
    Discourse 如何添加 Google Analytics GA4 代码
    Docker 引擎
    Docker 引擎
    Docker 引擎
    Docker 引擎概述
  • 原文地址:https://www.cnblogs.com/Clin/p/4885978.html
Copyright © 2020-2023  润新知