             else {
                 button.setTitle(showsHint ? state?.pin?.uppercased()[i] : nil, for: .normal)
                 button.setTitleColor(.lightGray, for: .normal)
-            }
-        }
-    }
-}
+                
+                let isFocussed = textField.isFirstResponder && i == textField.text?.characters.count ?? 0
+                if isFocussed {
+                    button.layer.borderColor = UIColor.black.cgColor
+                }
+            }
+        }
+    }
+}

        button.backgroundColor = .white
        button.layer.cornerRadius = 2
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.lightGray.cgColor
        return button
    }
    

        let showsHint = state?.showsHint == true
        
        for (i, button) in buttons.enumerated() {
            button.layer.borderColor = UIColor.lightGray.cgColor

            if let newCharacter = textField.text?[i],
                newCharacter != "" {
                button.setTitle(newCharacter, for: .normal)
