gpt4 book ai didi

ios - UITextView exclusionPaths 右下角

转载 作者:行者123 更新时间:2023-11-29 12:17:55 26 4
gpt4 key购买 nike

我正在尝试为消息做一些 whatsapp 之类的事情,让一个单元格根据内容大小调整大小,并在右下角显示日期...问题是我不知道被排除的矩形位置路径,因为文本是动态的,我有这样的东西,但只适用于多行,而不适用于单行:

whatsapp messages window

NSString *txt=@"I'm writing ";//a text renderer using Core Text, and I discovered I’ll need to wrap text around objects (such as is done in any DTP program). I couldn’t find any easy answers as to how to do this in the documentation, so having finally got it working I’ll share what I did. To lay out text in a custom shape in Core Text, you can pass a CGPath in when you create your CTFramesetterRef. Originally this only supported rectangular paths, but now it supports fully custom paths. My first thought was to see if I could subtract the region to wrap around from the path for my frame’s border, and pass the result in to Core Text as a path. It turns out firstly that subtracting one path from another in Core Graphics is not trivial. However, if you simply add two shapes to the same path, Core Graphics can use a winding rule to work out which areas to draw. Core Text, at least as of iOS 4.2, can also use this kind of algorithm. This will work for many cases: if you can guarantee that your object to be wrapped will be fully inside the frame (and not overlapping the edge), just go ahead and add its border to the same path as your frame, and Core"; // Text will do the rest.";

txtText.text=txt;

CGSize textFrame = [txtText sizeThatFits:CGSizeMake(235, MAXFLOAT)];

UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(textFrame.width-35, textFrame.height-20, 35, 20)];
txtText.textContainer.exclusionPaths = @[imgRect];

textFrame = [txtText sizeThatFits:CGSizeMake(235, MAXFLOAT)];

//int frameWidth=375;

txtText.frame=CGRectIntegral(CGRectMake(10, 10, textFrame.width, textFrame.height));
lblHour.frame=CGRectIntegral(CGRectMake(textFrame.width-35, textFrame.height-15, 35, 20));

viewCanvasAround.frame=CGRectIntegral(CGRectMake(50, 100, textFrame.width+20, textFrame.height+20));

最佳答案

我也遇到了同样的问题。我添加了带有 textAttachment 的 attributedString,它有一个大小。您将设置估计的最大大小。单线也没问题。(对不起,我英语不好。)

这是示例代码。

var text: String! {
didSet {

let font = UIFont.systemFont(ofSize: 13);
let att = NSMutableAttributedString.init(string: text, attributes: [NSAttributedString.Key.foregroundColor : UIColor.black,
NSAttributedString.Key.font : font]);
let attachment = NSTextAttachment.init(data: nil, ofType: nil);
var size = extraSize;
size.height = font.lineHeight;
attachment.bounds = CGRect.init(origin: CGPoint.init(), size: size);

att.append(NSAttributedString.init(attachment: attachment));

textView.attributedText = att;
}
}

关于ios - UITextView exclusionPaths 右下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31545730/

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