Swift Coding Summary 2

1. How does swift hide the quicktype keyboard toolbar on the iPad?

let item = textField.inputAssistantItem
        item.leadingBarButtonGroups = [UIBarButtonItemGroup]()
        item.trailingBarButtonGroups = [UIBarButtonItemGroup]()
        textField.autocorrectionType = .no

2.dismiss the current controller jump:

@IBAction func customMoneyClick(_ sender: Any) {
        self.dismiss(animated: true) {
            self.delegate?.gotoCustomMoney()
        }
    }

3. Customize the jump controller:

init(withType type: LoginOrRegisterType) {
        loginOrRegisterType = type
        super.init(nibNam.e: nil, bundle: nil)
        modalPresentationStyle = .custom
    }

4. Regular judgment:

fileprivate func isValideRegisterName(_ registerName: String) -> Bool {
        
        let partenPrefix = " ^[a-zA-Z\\u4e00-\\u9fa5]{1}.* "  // The first letter cannot be a number 
        let parttenValideChar = " ^[a-zA-Z0-9\\u4e00-\ \u9fa5_]+$ "  // Illegal characters only allow letters, Chinese characters, numbers, and underscores 
        let partenLength = " ^[a-zA-Z0-9\\u4e00-\\u9fa5_]{2,16}$ "  // Length 2 - 16
        
        
        
        var predicate = NSPredicate(format: "SELF MATCHES %@", parttenPrefix)
        if !predicate.evaluate(with: registerName) {
            HUDManager.showAutoDismissFailedMessage(GLOBAL_LANGUAGE( "The first letter of the nickname can only be letters or Chinese characters! " ))
             return  false
        }
}

5.CollectionView achieves the lowest vertical spacing:

 let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 3.0
        layout.minimumInteritemSpacing = CGFloat.leastNormalMagnitude

6.button.isExclusiveTouch = true

The role of ExclusiveTouch is: it can achieve the exclusivity when multiple controls on the same interface accept events, thereby avoiding bugs. That is to say, to avoid clicking multiple UIButtons on an interface at the same time, causing multiple methods to be responded to at the same time.

Use this to control the ExclusiveTouch property of UIButton, which needs to be set on each controller. A sentence can be used to replace such a setting, add [[UIButton appearance] setExclusiveTouch:YES]; when AppDelegate starts the application

7.Kingfisher setting picture:

backgroundImageView.kf.setImage(with: URL(string: imageUrlStr),
                              placeholder: UIImage(named:"qianrenqianwei"),
                              options: [.transition(ImageTransition.fade(1)), .keepCurrentImageWhileLoading])

8. The difference between super.init() method before and after writing:

Writing first is to take the initialization method of the parent class first, and put it in the back, it will cover the subclass, it is best to write it in the front.

9.UIStackView code uses:

let stackView: UIStackView = {
        let view = UIStackView(frame: CGRect.zero)
        view.axis = .horizontal       // The layout direction of the 
        subviews view.alignment = .center   // The alignment of the 
        subviews view.distribution = .fillEqually     // The distribution ratio (size) of the subviews The height or width of each subview is maintained Consistent. 
        return view
    }()

10.isEmpty function:

// create empty string using string literal 
var stringA = ""

if stringA.isEmpty {
   print( " stringA is empty " )
} else {
   print( " stringA is not empty " )
}

// Instantiate the String class to create an empty string 
let stringB = String()

if stringB.isEmpty {
   print( " stringB is empty " )
} else {
   print( " stringB is not empty " )
}
Output: stringA is empty stringB is empty

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324911897&siteId=291194637