Add a prefix to UITextField

后端 未结 4 1555
故里飘歌
故里飘歌 2021-01-22 02:18

I want a \'$\' Sign in the text field which cannot be erased. A user should be able to enter values after it and if he presses backspace it should only erase the value he entere

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 02:45

    No need to use shouldChangeCharactersInRange delegate method. The easiest and most convenient solution is this

                var label = UILabel(frame: CGRectMake(0, 0, 50, 50))
                label.text = "$";
                label.backgroundColor = UIColor(white: 0.0, alpha: 0.0)
                tenantField.rightViewMode = .Always
                tenantField.rightView = label
    

提交回复
热议问题