ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.86k stars 1.7k forks source link

YYLabel中使用YYTextBorder为什么不能对齐 #522

Open afishhhhh opened 8 years ago

afishhhhh commented 8 years ago

我放在了一个cell里,结果是这样的

2016-10-07 20 37 24
- (void)configure {
       NSMutableAttributedString *text = [NSMutableAttributedString new];
       NSArray *tags = @[@"red", @"orange", @"yellow", @"green", @"blue", @"purple", @"gray"];
       for (int i = 0; i < [tags count]; i++) {
        NSString *tag = [tags objectAtIndex:i];
        NSMutableAttributedString *tagText = [[NSMutableAttributedString alloc] initWithString:tag];
        tagText.yy_color = [UIColor whiteColor];
        [tagText yy_insertString:@"     " atIndex:0];
        [tagText yy_appendString:@"     "];

        YYTextBorder *border = [YYTextBorder new];
        border.fillColor = [UIColor redColor];
        border.cornerRadius = 100;
        border.lineJoin = kCGLineJoinBevel;

        border.insets = UIEdgeInsetsMake(-4, -16, -4, -16);
        [tagText yy_setTextBackgroundBorder:border range:[tagText.string rangeOfString:tag]];

        [text appendAttributedString:tagText];
    }
    text.yy_lineSpacing = 10;
    text.yy_lineBreakMode = NSLineBreakByWordWrapping;
    text.yy_font = [UIFont systemFontOfSize:18];

    YYLabel *label = [YYLabel new];
    label.attributedText = text;
    label.numberOfLines = 0;

    [self.contentView addSubview:label];

    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
        make.height.mas_equalTo(100);
    }];
}
afishhhhh commented 8 years ago

@ibireme

hllGitHub commented 6 years ago

@ibireme 希望可以有解决方案,谢谢!