Skip to content

addAttributeCharacterSpacing and addAttributeAlignmentStyle function did not work #152

Description

@bright135

eg: in LinkTextViewController.m , i will add addAttributeCharacterSpacing and addAttributeAlignmentStyle function
TYAttributedLabel *label1 = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(0, 64, CGRectGetWidth(self.view.frame), 0)];
label1.delegate = self;
label1.highlightedLinkColor = [UIColor orangeColor];
[self.view addSubview:label1];
NSString *text = @"\t总有一天你将破蛹而出,成长得比人们期待的还要美丽。\n\t但这个过程会很痛,会很辛苦,有时候还会觉得灰心。\n\t面对着汹涌而来的现实,觉得自己渺小无力。\n\t但这,也是生命的一部分,做好现在你能做的,然后,一切都会好的。\n\t我们都将孤独地长大,不要害怕。";

NSArray *textArray = [text componentsSeparatedByString:@"\n\t"];
NSArray *colorArray = @[RGB(213, 0, 0, 1),RGB(0, 155, 0, 1),RGB(103, 0, 207, 1),RGB(209, 162, 74, 1),RGB(206, 39, 206, 1)];
NSInteger index = 0;

for (NSString *text in textArray) {

if (index == 2) {
    // 追加链接信息
    [label1 appendLinkWithText:text linkFont:[UIFont systemFontOfSize:15+arc4random()%4] linkData:@"http://www.baidu.com"];
}else {
    // 追加文本属性
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];
    [attributedString addAttributeTextColor:colorArray[index%5]];
    [attributedString addAttributeFont:[UIFont systemFontOfSize:15+arc4random()%4]];
    [label1 appendTextAttributedString:attributedString];
    [attributedString addAttributeCharacterSpacing:10];
    [[attributedString addAttributeAlignmentStyle:kCTTextAlignmentLeft lineSpaceStyle:40.0 paragraphSpaceStyle:40.0 lineBreakStyle:kCTLineBreakByWordWrapping];
}
[label1 appendText:@"\n\t"];
index++;

}

[label1 appendLinkWithText:@"百度一下" linkFont:[UIFont systemFontOfSize:15+arc4random()%4] linkData:@"http://www.baidu.com"];

[label1 sizeToFit];
_label1 = label1;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions