Texture(AsyncDisplayKit)

作者: Mark_大东 | 来源:发表于2018-06-12 11:50 被阅读0次

    链马3.0进行大版本的UI更改,借此机会使用Texture进行页面UI的渲染,同时也发现了一些于以往不一样的方式比如布局:网页结构的布局设计思想,这个比较难理解;ASTextNode的对齐方式也是一个问题,值得惊喜的是的ASButtonNode解决了图文混排的问题(ps:对于一些简单的视图)。

    ASTextNode

    经常用UILable做为渲染文本的控件时会比较偏爱左对齐,右对齐,居中对齐等方式,但是ASTextNode找不到直接属性调用这样比较烦,写个方法来解决这个问题如下:

    + (NSMutableAttributedString *)stringWithFont:(UIFont *)font andColor:(UIColor *)color andText:(NSString *)text andRangeString:(NSString *)rangeStrig andAlign:(NSTextAlignment)alignment andRangeFont:(UIFont *)rangeFont andRangeColor:(UIColor *)rangeColor{
        NSMutableAttributedString *attrString   = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:color}];
        NSString *behind = [NSString stringWithFormat:@"%@",rangeStrig];
        NSRange range = [[attrString string] rangeOfString:behind];
        [attrString addAttribute:NSForegroundColorAttributeName
                           value:rangeColor
                           range:range];
        [attrString addAttribute:NSFontAttributeName value:rangeFont range:range];
        NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
        paragraphStyle.alignment                = alignment;
        [attrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attrString.length)];
        return attrString;
    }
    

    ASButtonNode

    ASButtonNode的出现解决了简单图文混排的问题如下图:

    image

    如图上的24H涨幅、最新价、净流入等都可以完美的解决,不仅省代码还提升了性能,简单的设置方法如下:

    self.latestButton                            = [[ASButtonNode alloc]init];
    [self.latestButton setTitle:@"最新价" withFont:PINGFANGSC_REGULAR(12) withColor:RGB_COLOR(113,126, 137) forState:UIControlStateNormal];
    self.latestButton.contentHorizontalAlignment = ASHorizontalAlignmentLeft;
    [self.latestButton setImage:[UIImage imageNamed:@"paixu"] forState:UIControlStateNormal];
    self.latestButton.imageAlignment             = ASButtonNodeImageAlignmentEnd;
    self.latestButton.contentSpacing             = 4;
    [self.latestButton addTarget:self action:@selector(newClickEvent)forControlEvents:ASControlNodeEventTouchUpInside];
    

    相关文章

      网友评论

        本文标题:Texture(AsyncDisplayKit)

        本文链接:https://www.haomeiwen.com/subject/xjuleftx.html