Hide the Cursor of a Uitextfield

Hide the cursor of a UITextField

Simply subclass UITextField and override caretRectForPosition

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
return CGRectZero;
}

Disable blinking cursor from UITextField in swift?

First you need to confirm to UITextFieldDelegate and then set you textField like yourTextField.delegate =self
add
yourTextField.resignFirstResponder()

to your code. Call resignFirstResponder to yourTextField.
and you can also use below code (According to your need).

In delegate method textFieldDidEndEditing(textField: UITextField) with checking (if) whether it has some value/text of not.

yourTextField.attributedPlaceholder = NSAttributedString(string: "User Name", attributes: [NSForegroundColorAttributeName: UIColor.whiteColor()]) textUserName.resignFirstResponder()

Hide cursor on UITextView - Swift

Try this:

1) Add a tap gesture recogniser to your view in an appropriate place (viewDidLoad for example)

  let tapRecognizer = UITapGestureRecognizer(target: self, action: "hideKeyboard")
view.addGestureRecognizer(tapRecognizer)

2) Then you need to add hideKeyboard method. Example implementation

func hideKeyboard() {
view.endEditing(true)
}

That should do it :)

How to hide a blue cursor in a textfield and a keyboard?

The textfield cursor color is based on the default tint color. In your case it's blue. I would change the tint color to clear color.

linkField.tintColor = UIColor.clearColor()

For the edited question, if you just want to dismiss the keyboard then

linkField.resignFirstResponder()

will dismiss the keyboard and when you want focus again use

linkField.becomeFirstResponder()

On swift, how to hide cursor and disable cut/paste for UITextfield programmatically

Add this methods to your code and see the changes. You can also customize what you can do with your textfield. If you want all textfield actions to be disabled then just "return false" in func canPerformAction method.

override func caretRect(for position: UITextPosition) -> CGRect {
return CGRect.zero
}

override func selectionRects(for range: UITextRange) -> [UITextSelectionRect] {
return []
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.cut(_:)) || action == #selector(UIResponderStandardEditActions.selectAll(_:)) || action == #selector(UIResponderStandardEditActions.paste(_:)) {
return false
}
// Default
return super.canPerformAction(action, withSender: sender)**

Prevent editing of text in UITextField and hide cursor/caret/magnifying glass while using an inputView

Subclass UITextField

//Disables caret
- (CGRect)caretRectForPosition:(UITextPosition *)position
{
return CGRectZero;
}

//Disables magnifying glass
-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]])
{
gestureRecognizer.enabled = NO;
}
[super addGestureRecognizer:gestureRecognizer];
}

In your UITextFieldDelegate

//Prevent text from being copied and pasted or edited with bluetooth keyboard.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return NO;
}

Now just set your text programmatically from the result of your UIPickerView/UIDatePicker.

UITextField hide placeholder text or bring cursor to front when clicked swift

First thing make sure you set the delegate of the text field either from storyboard or set it in the viewDidLoad()

And change your code to this

userTextField.placeholder = ""
passwordTextField.placeholder = ""

Always Display Cursor UITextField

@andreamazz answer in Swift.

UITextField show cursor even when userInteractionEnabled is set to NO

UIView.animateWithDuration(1, delay: 0, options: .Repeat, animations: {() -> Void in
cursorView.alpha = 0 }, completion: {(animated: Bool) -> Void in
cursorView.alpha = 1
})

UITextField leave the cursor, remove the keyboard

This should do the trick:

textField.inputView = UIView()

Swift 2 and above



Related Topics



Leave a reply



Submit