When mixed iOS development Graphic Solutions

In a recent development projects, met with mixed graphic needs, there are mixed prior to graphic understand, but just look for the code, can make do. Considering the team often encounter in the late mixed graphic needs, I here refer to the online blog, compiled a
reference blog address:
https://blog.csdn.net/sinat_27706697/article/details/46270939
HTTPS: //blog.csdn.net/sinat_27706697/article/details/46286717?utm_source=blogxgwz4
currently function can be achieved, customize text size, font, color, line spacing, graphic mixed. If you need separate treatment for a sentence of text, you can configure json. The rest go inside the default config configuration.
Using the following code:

- (void)viewDidLoad
{
    [super viewDidLoad];
	CTDisplayView *ctView = [[CTDisplayView alloc] initWithFrame:CGRectMake(0, 200, 300, 0)];
        ctView.backgroundColor = [UIColor whiteColor];
        CTFrameParserConfig *config = [[CTFrameParserConfig alloc] init];
        config.width = 300;
        config.fontSize = 30.0f;
        config.lineSpace = 8.0f;
       config.bgColor = [UIColor redColor];

        CoreTextData *data = [CTFrameParser parseArray:[self array] config:config];
        ctView.data = data;
        ctView.frame = CGRectMake(0, 200, 300, data.height);
        [self.view addSubview:ctView];
    
    }


    - (NSArray *)array
    {
        return @[
            @{@"type":@"txt",
              @"content":@"曾经有一份真挚的爱情摆在我面前,我没有珍惜",
              @"bgColor":@"#f1f1f1",//可以不设置
//              @"size":@"16"
//              @"color":@"#000000"
            },
            @{@"type":@"txt",
              @"content":@"知道失去之后才后悔莫及",
              @"size":@"18"
//              @"color":@"#000000"
            },
            @{@"type":@"txt",
              @"content":@"如果上天能给我再来一次的机会的话,我会对那个女孩说三个字:我爱你",
              @"size":@"24"
//              @"color":@"#000000"
            },
            @{@"type":@"txt",
              @"content":@"如果非要在这份爱上加个期限的话:我希望是一万年",
              @"size":@"18"
//              @"color":@"#000000"
            },
            @{
                  @"type":@"img",
                  @"name":@"icon.png",
                  @"width":@"30",
                  @"height":@"20"
            }
        ];
    }

Pod can be used to integrate

pod 'JKCoreTextKit'

The library there is still much room for optimization upgrade, we welcome a lot of criticism and exhibitions. There are good ideas and suggestions can private letter I

More technical articles can be scanned under dry Fanger Wei code:
Here Insert Picture Description

Published 231 original articles · won praise 110 · Views 600,000 +

Guess you like

Origin blog.csdn.net/HHL110120/article/details/103041741