gpt4 book ai didi

ios - 从标签中删除缩进

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:54 24 4
gpt4 key购买 nike

我有一个标签,其中第一个单词以缩进开头。我不希望段落以缩进开头。

我需要这样的东西:

LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsum
LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsum
LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsum
LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsum.

我要去哪里:

   LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsum
LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumm
LoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsumLoremIpsum.

我正在使用以下代码:

UILabel *b1Lab1=[[UILabel alloc] initWithFrame:CGRectMake(8,108,124,90)];

NSString *strr =[aPostIntro objectAtIndex:indexPath.section*2];
if(strr.length > 270)
{
strr = [[strr substringToIndex:270] stringByAppendingString:@"..."];
}

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.paragraphSpacingBefore = 0;
paragraphStyle.alignment = NSTextAlignmentJustified;

NSAttributedString *string1 = [[NSAttributedString alloc] initWithString:strr
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
paragraphStyle, NSParagraphStyleAttributeName ,
[NSNumber numberWithFloat:0],NSBaselineOffsetAttributeName,
nil]];
b1Lab1.attributedText = string1;

// NSString *stri = [aPostIntro objectAtIndex:indexPath.section];

b1Lab1.lineBreakMode = NSLineBreakByWordWrapping;
b1Lab1.numberOfLines = 9;
b1Lab1.font = [UIFont fontWithName:@"Helvetica" size:8];
b1Lab1.tag=111;
b1Lab1.textColor = [UIColor blackColor];

最佳答案

检查:

NSString *strr =[aPostIntro objectAtIndex:indexPath.section*2];
NSLog(@"%@",strr); //check strr

并确认 strr 本身不包含任何起始空格。


如果将 strr 替换为:

strr = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat..."

输出符合您的预期。

关于ios - 从标签中删除缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20279944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com