小编Pav*_*los的帖子

如何在Swift中禁用键盘上的"Space"键?

我正在创建一个登录系统,我不希望在用户名字段中允许使用空格.我想阻止添加空格,而不是检查和验证字段.

因此,每次用户按空格键时,都不会发生任何事情.我怎样才能做到这一点?我见过Instagram这样做.

到目前为止这是我的代码:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var signUp: UIBarButtonItem!
    @IBOutlet weak var navBar: UINavigationBar!
    @IBOutlet weak var UsernameText: UITextField!


    override func viewDidLoad() {
        super.viewDidLoad()

             self.navigationController?.navigationBar.clipsToBounds = true
        UsernameText.attributedPlaceholder = NSAttributedString(string:"TypeYourUsername",
            attributes:[NSForegroundColorAttributeName: UIColor.whiteColor()])

        func textField(UsernameText: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
            if (string == " ") {
                return false
            }
            return true
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func …
Run Code Online (Sandbox Code Playgroud)

keyboard ios swift

11
推荐指数
3
解决办法
7991
查看次数

如何在行的滑动操作配置中为VoiceOver添加辅助功能标签?

我正在使用Swift 4创建一个iOS应用程序而我没有使用Storyboard.要从Table View Controller中删除行,用户会向左滑动该行,然后单击"删除"按钮.

这是我用来实现的代码(没有使用外部库):

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    self.isAccessibilityElement = true
    self.accessibilityLabel = "Delete row"


    let deleteAction = UIContextualAction(style: .normal , title: "DELETE") { (action, view, handler) in

        self.removeRowFromMyList(indexPath: indexPath.row)

        MyListController.stations.remove(at: indexPath.row)
        self.tableView.deleteRows(at: [indexPath], with: .automatic)

        self.tableView.setEditing(false, animated: true)
        self.tableView.reloadData()
    }
    let swipeAction = UISwipeActionsConfiguration(actions: [deleteAction])
    swipeAction.performsFirstActionWithFullSwipe = false

    return swipeAction
}
Run Code Online (Sandbox Code Playgroud)

我确实检查了其他问题,但没有一个问题可以解决.如有任何其他解决此问题需要了解的信息,请随时在此处发表评论.谢谢 :)

ios swift

5
推荐指数
1
解决办法
1409
查看次数

标签 统计

ios ×2

swift ×2

keyboard ×1