【ios开发/Xcode】实现登录注册

【ios开发/Xcode】实现登录注册

实现效果

首先进入初始界面,输入账号Linchuantao,密码Linchuantao,显示登录失败(如下左图),因此需要进行注册,点击左下角注册,输入账号Linchuantao,密码Linchuantao,点击注册
在这里插入图片描述
之后再次通过账号Linchuantao,密码Linchuantao进行登录,登录成功
在这里插入图片描述

源代码

登录界面代码 ViewController.swift

//1.登录界面代码
//  ViewController.swift
//
//  Created by JMU文科状元 on 2021/11/21.
//  Copyright © 2021 JMU文科状元. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    let userNameLabel = UILabel(frame:CGRect(x:50,y: 300, width: 200, height: 50))
    let passwordLabel = UILabel(frame:CGRect(x:50,y: 385, width: 100, height: 50))
    let enterUser = UITextField(frame: CGRect(x: 140, y: 310, width: 200, height: 40))
    let enterPassword = UITextField(frame: CGRect(x: 140, y: 390, width: 200, height: 40))
    var user = Dictionary<String,String>()
    let loginBtn = UIButton(type: .system)
let regBtn = UIButton(type: .system)

//定义一些button与text的默认值等数据
    override func viewDidLoad() {
        super.viewDidLoad()
        userNameLabel.text = "用户名"
        passwordLabel.text = "密码"
        userNameLabel.textColor=UIColor.darkGray        
        passwordLabel.textColor=UIColor.darkGray        
        self.view.addSubview(userNameLabel)
        self.view.addSubview(passwordLabel)
        enterUser.borderStyle = UITextField.BorderStyle.roundedRect
        enterPassword.borderStyle = UITextField.BorderStyle.roundedRect
        enterPassword.isSecureTextEntry = true
        enterUser.placeholder="请输入用户名" 
        enterPassword.placeholder="请输入密码"
        enterUser.clearButtonMode=UITextField.ViewMode.whileEditing
        enterPassword.clearButtonMode=UITextField.ViewMode.whileEditing
        
        self.view.addSubview(enterUser)
        self.view.addSubview(enterPassword)
        loginBtn.frame = CGRect(x: 85, y:450, width: 100, height: 50)
        regBtn.frame = CGRect(x: 200, y:450, width: 100, height: 50)
        loginBtn.setTitle("登录", for: .normal)
        loginBtn.addTarget(self, action: #selector(ViewController.mapForLogin(_:)), for: UIControl.Event.touchUpInside)
        regBtn.setTitle("注册", for: .normal)
        self.view.addSubview(loginBtn)
        
        regBtn.addTarget(self, action: #selector(ViewController.openViewController), for: .touchUpInside)
        self.view.addSubview(regBtn)
    }
    
    @objc func openViewController()
    {
        let loginView = ViewController1()
        loginView.viewController = self
        self.present(loginView, animated: true, completion: nil)
    }
    
    @objc func mapForLogin(_ button:UIButton)
    {
        if user[enterUser.text!]==enterPassword.text{
            let alertController = UIAlertController(title: "登录成功!",message: nil, preferredStyle: .alert)
            self.present(alertController, animated: true,completion: nil)
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {self.presentedViewController?.dismiss(animated: false, completion: nil)}
        }
        else{
            let alertController = UIAlertController(title: "登录失败!",message: nil, preferredStyle: .alert)
            self.present(alertController, animated: true,completion: nil)
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {self.presentedViewController?.dismiss(animated: false, completion: nil)}
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
}

注册界面代码

//2.注册界面代码
//  ViewController1.swift
//
//  Created by JMU文科状元 on 2021/11/21.
//  Copyright © 2021 JMU文科状元. All rights reserved.
//

import UIKit

class ViewController1: UIViewController {
    let userNameLabel = UILabel(frame:CGRect(x:50,y: 100, width: 200, height: 50))
    let passwordLabel = UILabel(frame:CGRect(x:50,y: 180, width: 100, height: 50))
    let enterUser = UITextField(frame: CGRect(x: 140, y: 110, width: 200, height: 40))
    let enterPassword = UITextField(frame: CGRect(x: 140, y: 190, width: 200, height: 40))
    let regBtn = UIButton(type: .system)
    let returnBtn = UIButton(type: .system)//返回
    weak var viewController : ViewController?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        userNameLabel.text = "用户名"
        passwordLabel.text = "密码"
        userNameLabel.textColor=UIColor.darkGray
        passwordLabel.textColor=UIColor.darkGray
        self.view.addSubview(userNameLabel)
        self.view.addSubview(passwordLabel)
        
        enterUser.borderStyle = UITextField.BorderStyle.roundedRect
        enterPassword.borderStyle = UITextField.BorderStyle.roundedRect
        enterPassword.isSecureTextEntry = true
        
        enterUser.placeholder="请输入用户名" //提示内容
        enterPassword.placeholder="请输入密码"
        enterUser.clearButtonMode=UITextField.ViewMode.whileEditing
        enterPassword.clearButtonMode=UITextField.ViewMode.whileEditing
        self.view.addSubview(enterUser)
        self.view.addSubview(enterPassword)
        regBtn.frame = CGRect(x: 100, y:250, width: 100, height: 50)
        regBtn.setTitle("注册", for: .normal)
        regBtn.addTarget(self, action: #selector(ViewController1.dismissSelf), for: .touchUpInside)
        self.view.addSubview(regBtn)
        returnBtn.frame = CGRect(x: 200, y:250, width: 100, height: 50)
        returnBtn.setTitle("返回", for: .normal)
for: .touchUpInside)
        self.view.addSubview(returnBtn)
    } 
    @objc func dismissSelf()
    {
        viewController?.user.updateValue(enterPassword.text!, forKey: enterUser.text!)
        self.dismiss(animated: true, completion: nil)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
}
  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
SIP(Session Initiation Protocol)是一种用于实时通信的协议,常用于语音通话、视频通话和即时消息传递。IOS开发SIP应用需要使用第三方库或框架来实现SIP协议。 以下是IOS开发SIP应用的一般步骤: 1. 选择合适的SIP库或框架,目前比较流行的有pjsip、Linphone、Siphon等。 2. 下载并安装所选库或框架。 3. 创建Xcode项目,并在项目中添加所选库或框架的头文件和库文件。 4. 配置SIP服务器信息,包括服务器地址、端口、用户名、密码等。 5. 实现SIP协议的各种功能,如注册、呼叫、接听、挂断等。 6. 实现音频和视频的采集、编解码、传输等功能。 7. 实现即时消息传递功能,包括文本、图片、文件等。 8. 测试并调试应用,确保其功能正常。 9. 发布应用到App Store,供用户下载和使用。 在实现IOS开发SIP应用时,需要注意以下几点: 1. SIP应用需要使用网络进行通信,因此需要保证网络连接的稳定性和安全性。 2. SIP应用需要使用麦克风和摄像头等硬件设备进行音视频采集和传输,因此需要考虑设备兼容性和性能问题。 3. SIP应用需要与其他SIP应用互通,因此需要考虑与其他SIP应用的兼容性和互操作性。 4. SIP应用需要保护用户的隐私和安全,因此需要采取相应的安全措施,如加密传输、用户认证等。 总之,IOS开发SIP应用需要具备一定的网络通信、音视频处理和安全保障方面的知识,同时需要熟悉所选SIP库或框架的使用方法和API。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值