Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

on edit input field provide default value if textfield get empty swift

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    guard let textFieldString = textField.text, let range = Range(range, in: textFieldString) else {
        return false
    }
    let newString = textFieldString.replacingCharacters(in: range, with: string)
    if newString.isEmpty {
        textField.text = "0"
        return false
    } else if textField.text == "0" {
        textField.text = string
        return false
    }
    return true
}
Comment

PREVIOUS NEXT
Code Example
Swift :: get character at specifiic location swift 
Swift :: Swift Access Elements from Dictionary 
Swift :: swift get error from the from completion 
Swift :: Swift Function With Argument Label 
Swift :: how to call another view controller method when button click from another ios swift 
Swift :: chevrondownf6a06a60-2122-49d0-86a0-03ba8c532aec 
Swift :: Swift Explicitly declaring an unwrapped optional 
Swift :: Swift Loop Statements 
Swift :: Swift Labeled Statement with break 
Swift :: Swift enum Associated Values 
Swift :: swift 5 full screen image viewer 
Swift :: Named Associated Values Swift 
Swift :: library not found for -lalan-sdk-react-native 
Swift :: Swift Code Blocks 
Swift :: Swift Logical Operators 
Swift :: swift await async 
Ruby :: how to get tables list in rails 
Ruby :: how to delete a table in rails 
Ruby :: rails trackable to devise 
Ruby :: index name is too long rails 
Ruby :: ruby each with index 
Ruby :: rails remove foreign key 
Ruby :: how to create a database in production mode rails 
Ruby :: auto load path rails 
Ruby :: ruby generate uuid 
Ruby :: rails send email from console 
Ruby :: rails generate controller no respec 
Ruby :: dictionary ruby 
Ruby :: rails image disappears after showing 
Ruby :: rails not_found 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =