iOS Development-Login Interface Development (6) use of Toast-swift-swfit4.1_xcode9.3.1

Source: Internet
Author: User

First look at the effect:

1. Before we made the login interface UI, implemented the network request, if the user entered the wrong VIP number, should prompt the user "VIP number is incorrect"

2. In Android, we have toast can be used directly, in iOS, seemingly no such native controls, then we introduce a third open source framework:

Toast-swift

3. Let's revise the Podfile:

/users/jimi/documents/ios/demo/logindemo/podfile
# Settings support minimum platform Platform:ios, ' 8.0 ' target ' logindemo ' do# if it is a swift project, add "use_frameworks!" use_frameworks!# If you want to use a fixed version you can write as follows # pod ' afnetworking ', ' ~> 3.2.1 ' pod ' afnetworking ' pod ' swiftyjson ' pod ' Toast-swift ', ' ~> 3.0.1 ' end

4. Open the terminal and re-introduce the third-party framework (you can see that the introduced Afnetworking/swiftyjson will not be reinstalled, only the newly added toast-swift will be installed):

jimidemacbook-pro:~ jimi$ cd/users/jimi/documents/ios/demo/logindemojimidemacbook-pro:logindemo jimi$ pod Installanalyzing dependenciesdownloading dependenciesusing afnetworking (3.2.1) Using Swiftyjson (4.1.0) Installing Toast-swift (3.0.1) generating Pods projectintegrating client projectsending statspod installation complete! There is 3 dependencies from the Podfile and 3 total pods installed.

5. Introduced in the project, and called, we use the simplest way (complex way, also chrysanthemum turns and pictures of toast):

Import Toast_swift

6. After the introduction, as usual to press, COMMAND+B, recompile the project. The following is the complete login controller:

Import Uikitimport swiftyjsonimport toast_swiftclass Viewcontroller:uiviewcontroller {@IBOutlet weak var et_v ip_code:uitextfield! VIP number @IBOutlet weak var bt_login:uibutton! Login button override Func Viewdidload () {super.viewdidload ()//Do any additional setup after loading the VI    EW, typically from a nib. } override func Didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any resources t    Hat can be recreated. }//Login button click event @IBAction func bt_login_clicked (_ Sender:any) {//Create request parameter//Let params = ["Vip_k Eyworld ":" 595466 "," Password ":" 123456 "]//Multiple parameter notation/let params = [" Vip_keyworld ":" 595466 "] let Vipco        De = et_vip_code.text! let params = ["xxx": Vipcode]//request parameter Let loginurl = "http://www.xxx.com/xxx/xxxx.asp"//Request address//Use Afnetworking sends a POST request NetworkTools.shareInstance.request (Methodtype:. POST, Urlstring:loginurl, ParametErs:params as [String:anyobject]) {(Result:anyobject, error:error?) in if error! = Nil {                Print (error!)                                    return} print (result!) Using Swiftyjson parsing JSON--here is jsonobject//If you want to parse Jsonarray, Swiftyjson more silky, refer to Http://www.hangge.com/blog                /cache/detail_968.html Let JSON = JSON (result as any) if let vip_id = json["id"].string {  Print ("ID is:", vip_id) self.view.makeToast ("id =" + vip_id)//Toast prompt if vip_id = = "0" {self.view.makeToast ("Please enter the correct VIP number")//Toast prompt}else{self.view.ma Ketoast ("Login Successful")//Toast Prompt}}}}//Input box content change Listener @IBAction func et_vip_cod        E_changed (_ Sender:any) {Let Vipcode = et_vip_code.text! If Vipcode.count > 0 {bt_login.backgroundcolor = #colorLiteral (red:0.1921568627, green:0.5411764706, Blue:1, alpha:1)//entered VIP number login button background color} else{bt_login . backgroundcolor = #colorLiteral (red:0.3137254902, green:0.3921568627, blue:0.5137254902, alpha:1)//Do not enter VIP Number login button background Color}}}

7.toast-swift's GitHub Address:

Https://github.com/scalessec/Toast-Swift

8. Next, let's jump to the main interface from the login interface.

iOS Development-Login Interface Development (6) use of Toast-swift-swfit4.1_xcode9.3.1

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.