Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addAttributeCharacterSpacing and addAttributeAlignmentStyle function did not work #152

Open
bright135 opened this issue Jan 16, 2020 · 0 comments

Comments

@bright135
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant