hardik hardik - 7 months ago 24
Swift Question

ios: how to start cursor at specific position?

I want cursor at specific position.
I show my requirement in image.

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

Answer Source

my problem is solved by adding this simple line in viewdidload()

  self.txtroutine.layer.sublayerTransform = CATransform3DMakeTranslation(15, 0, 0);