swift 代码打开和关闭一个storyboard 页面

1.在storyboard里创建一个ViewController

 



 

 

2.写入如下代码

 

            print("弹出登录框")
            let loginViewController  = self.storyboard?.instantiateViewControllerWithIdentifier("login_view") as! LoginViewController
            presentViewController(loginViewController, animated: true, completion: nil)

 

3.LoginViewController.swift

import UIKit

class LoginViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}

 

4.关闭

self.dismissViewControllerAnimated(true, completion: nil)

 

 

结束

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
创建九宫格的步骤如下: 1. 创建一个新的 Xcode 项目,选择 Single View Application。 2. 在 Main.storyboard 中添加一个 UICollectionView。在 Attributes Inspector 中将 Scroll Direction 设置为 Vertical。 3. 在 UICollectionViewCell 中添加一个 UILabel,将其居中,并设置它的控制点约束(Control Point Constraints)为 0。 4. 在 Attributes Inspector 中将 Cell Size 设置为 100 x 100,Minimum Spacing 设置为 0。 5. 在 ViewController.swift 中添加以下代码: ``` import UIKit class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { @IBOutlet weak var collectionView: UICollectionView! let items = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] override func viewDidLoad() { super.viewDidLoad() collectionView.dataSource = self collectionView.delegate = self } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return items.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCell cell.label.text = items[indexPath.row] return cell } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { print("You selected cell #\(indexPath.item + 1)") } } class CustomCell: UICollectionViewCell { @IBOutlet weak var label: UILabel! } ``` 6. 在 Main.storyboard 中选择 UICollectionViewCell,将其 Class 设置为 CustomCell,并将 Identifier 设置为 cell。 这样,你就可以在模拟器中运行你的应用程序,看到一个九宫格了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值