gpt4 book ai didi

ios - 如何将按钮添加到文本末尾,如 Facebook 的 "Continue reading"?

转载 作者:可可西里 更新时间:2023-11-01 02:59:00 26 4
gpt4 key购买 nike

当状态帖子太长时,Facebook 应用程序会剪切文本并在末尾添加“继续阅读”。它怎么知道在哪里剪切文本并添加“...继续阅读”?

不仅仅是向 textView 或标签添加按钮,还有如何剪切字符串。例如,在下图中,我将行数限制为 7。我可以只在 textView 或标签的右下角放置一个按钮,但它可能会与某些字符重叠。

enter image description here

最佳答案

这应该对你有帮助:)

NSString *str=self.strQuestionTitle;

CGRect rect=CGRectMake(51, 16, 257, 0);

CGSize size=[str sizeWithFont:self.lblQuestion.font constrainedToSize:CGSizeMake(257, 3000) lineBreakMode:self.lblQuestion.lineBreakMode];
int lines=(size.height/self.lblQuestion.font.pointSize);
self.lblQuestion.numberOfLines=lines;
rect.size=size;
if(lines>2)
{
if(lines==3 &&[str length]>66)
{
str=[str substringToIndex:66];
str=[str stringByAppendingString:@"...Read More"];
size=[str sizeWithFont:self.lblQuestion.font constrainedToSize:CGSizeMake(257, 67) lineBreakMode:self.lblQuestion.lineBreakMode];

int lines=(size.height/self.lblQuestion.font.pointSize);
self.lblQuestion.numberOfLines=lines;

rect.size=CGSizeMake(257, 67);
}
else if(lines>3)
{
str=[str stringByAppendingString:@"...Read More"];
size=[str sizeWithFont:self.lblQuestion.font constrainedToSize:CGSizeMake(257, 67) lineBreakMode:self.lblQuestion.lineBreakMode


];

int lines=(size.height/self.lblQuestion.font.pointSize);
self.lblQuestion.numberOfLines=lines;

rect.size=CGSizeMake(257, 67);
}

//self.lblQuestion.lineBreakMode=NSLineBreakByTruncatingHead;
}

关于ios - 如何将按钮添加到文本末尾,如 Facebook 的 "Continue reading"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18386498/

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