Swift Code Summary 2

Source: Internet
Author: User

1.swift How can I hide the QuickType keyboard toolbar on my IPad?

Let item = textfield.inputassistantitem        = [Uibarbuttonitemgroup] ()        = [ Uibarbuttonitemgroup] ()        =. No

2.dismiss Current controller Jump:

@IBAction Func Custommoneyclick (_ Sender:any) {        true) {self            . delegate? . Gotocustommoney ()        }    }

3. Custom Jump Controller:

Init (Withtype type:loginorregistertype) {        = type        super.init (Nibnam.e:nil, Bundle:nil)         = . Custom    }

4. Regular judgment:

Fileprivate Func Isvalideregistername (_ registername:string)Bool {Let Parttenprefix="^[a-za-z\\u4e00-\\u9fa5]{1}.*" //The first letter cannot be a numberLet Parttenvalidechar ="^[a-za-z0-9\\u4e00-\\u9fa5_]+$" //illegal characters only allow letters, Chinese characters, numbers, underscoresLet Parttenlength ="^[a-za-z0-9\\u4e00-\\u9fa5_]{2,16}$" //length 2-16                                varpredicate = nspredicate (format:"Self MATCHES%@", Parttenprefix)if!predicate.evaluate (with:registername) {hudmanager.showautodismissfailedmessage (Global_language ("nickname initials can only be letters or kanji! "))            return false        }}

5.CollectionView achieves the lowest vertical interval:

Let layout = uicollectionviewflowlayout ()        3.0        = cgfloat.leastnormalmagnitude

6.button.isexclusivetouch = True

Exclusivetouch's role is to avoid bugs by achieving exclusivity when multiple controls on the same interface accept events. In other words, avoiding multiple uibutton at the same time on one interface causes multiple methods to respond simultaneously. Use this to control the Exclusivetouch property of the UIButton, which needs to be set on each controller. Use a word instead of this setting to add [[UIButton appearance] setexclusivetouch:yes] When Appdelegate launches the app;

7.Kingfisher Settings Picture:

BackgroundImageView.kf.setImage (With:url (string: imageurlstr),                              placeholder:uiimage (named: " Qianrenqianwei " ),                              options: [. Transition (Imagetransition.fade (1)),. Keepcurrentimagewhileloading])

8.super.init () method before writing the difference:

First write is to go first the parent class initialization method, put in the back, will handle the class of overrides, preferably written in front.

9.UIStackView Code Usage:

Let Stackview:uistackview = {        = Uistackview (frame:CGRect.zero)        =. Horizontal      // the layout direction of the child view        view.alignment =. Center  //  child view Alignment        view.distribution =. fillequally    //  sub-view distribution scale (size)  the height or width of each child view remains the same.         return  View    } ()

10.isEmpty function:

//create an empty string using string literalsvarStringa =""ifstringa.isempty {print ("Stringa is empty." )} Else{print ("Stringa is not empty." )}//instantiate the string class to create an empty stringLet STRINGB =String ()ifstringb.isempty {print ("stringb is empty." )} Else{print ("stringb is not empty.")} output: Stringa is empty stringb is empty

Swift Code Summary 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.