gpt4 book ai didi

ios:如何在特定位置启动光标?

转载 作者:行者123 更新时间:2023-11-30 12:30:36 25 4
gpt4 key购买 nike

我希望光标位于特定位置。我在图片中展示了我的要求。

 let arbitraryValue: Int = 5
if let newPosition = txtroutine.position(from: txtroutine.beginningOfDocument, offset: arbitraryValue) {

txtroutine.selectedTextRange = txtroutine.textRange(from: newPosition, to: newPosition)
}

my requirement

my default cursor position

最佳答案

我有类似的东西,但我的代码是 obj-c 的,希望你能用 swift 制作它,

获取光标当前位置

 - (NSInteger)cursorPosition
{
UITextRange *selectedRange = self.selectedTextRange;
UITextPosition *textPosition = selectedRange.start;
return [self offsetFromPosition:self.beginningOfDocument toPosition:textPosition];
}

//将光标设置在您的特定位置

- (void)setCursorPosition:(NSInteger)position
{
UITextPosition *textPosition = [self positionFromPosition:self.beginningOfDocument offset:position];
[self setSelectedTextRange:[self textRangeFromPosition:textPosition toPosition:textPosition]];
}

关于ios:如何在特定位置启动光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43603281/

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