Swift - WeChat

文件图例.png
去掉Main.png
  • 给每个视图(UIViewController)设置颜色

AppDelegate.swift代码如下:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame:UIScreen.main.bounds)
        self.window?.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
        self.window?.makeKeyAndVisible()
        //创建标签视图控制器
        let tabBarVC = MainTabBarController()
        //将标签视图控制器指定为window的根视图控制器
        self.window?.rootViewController = tabBarVC

        return true
    }

MainTabBarController.swift代码如下:

import UIKit

//屏幕的宽
let kScreenWidth = UIScreen.main.bounds.size.width
//屏幕的高
let kScreenHight = UIScreen.main.bounds.size.height

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.setupViewController()
    }
    func setupViewController(){
        //消息:Chats
        let chatVC = ChatViewController()

        let chatNC = UINavigationController(rootViewController: chatVC)

        chatVC.title = "Chats"

        chatVC.tabBarItem.image = UIImage(named: "tabbar_mainframe@2x.png")

        //通讯录:Contacts
        let contactVC = ContactViewController()

        let contactNC = UINavigationController(rootViewController: contactVC)

        contactVC.title = "Contacts"

        contactVC.tabBarItem.image = UIImage(named: "tabbar_contacts@2x.png")

        //发现:Discover
        let discoverVC = DiscoverViewController()

        let discoverNC = UINavigationController(rootViewController: discoverVC)

        discoverVC.title = "Discover"

        discoverVC.tabBarItem.image = UIImage(named: "tabbar_discover@2x.png")

        //我:Me
        let meVC = MeViewController()

        let meNC = UINavigationController(rootViewController: meVC)

        meVC.title = "Me"

        meVC.tabBarItem.image = UIImage(named: "tabbar_me@2x.png")

        self.viewControllers = [chatNC,contactNC,discoverNC,meNC]

        self.tabBar.tintColor = #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

MeViewController.swift代码如下:

import UIKit

class MeViewController: UITableViewController {

    let MeCellReuseIdentifer = "userCell"
    let chatSystemCell = "chatCell"
    let dataSource:[[String]] = [["相册","收藏","钱包","卡包"],["表情"],
["设置"]]
    override func loadView() {
        let tableView = UITableView(frame: UIScreen.main.bounds, style: .grouped)
        self.tableView = tableView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = #colorLiteral(red: 0.9568627477, green: 0.6588235497, blue: 0.5450980663, alpha: 1)
        self.tableView.register(UserCell.self, forCellReuseIdentifier: MeCellReuseIdentifer)
        self.tableView.register(ChactsystemCell.self, forCellReuseIdentifier: chatSystemCell)
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 4
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return section == 1 ? 4 : 1
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return indexPath.section == 0 ? 100 : 50
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //返回UserCell
        if indexPath.section == 0 {
            let cell = tableView.dequeueReusableCell(withIdentifier: MeCellReuseIdentifer) as! UserCell
            cell.userPic.image = #imageLiteral(resourceName: "头像.jpg")
            cell.userNameLable.text = "风的低语"
            cell.userIDLable.text = "微信号:fyl13314749700"
            cell.userQRView.image = #imageLiteral(resourceName: "二维码.jpg")
            return cell

        }else{//返回ChactsystemCell
            let cell = tableView.dequeueReusableCell(withIdentifier: chatSystemCell) as! ChactsystemCell
            let group = dataSource[indexPath.section - 1]
            let str = group[indexPath.row]
            cell.iconView.image = UIImage(named: str)
            cell.infoLable.text = str
            return cell
        }
    }

    /*
    // Override to support conditional editing of the table view.
    override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            // Delete the row from the data source
            tableView.deleteRows(at: [indexPath], with: .fade)
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
}

UserCell.swift代码如下:

import UIKit

class UserCell: UITableViewCell {
    //用户头像
    var userPic:UIImageView!
    //用户名
    var userNameLable:UILabel!
    //用户帐号
    var userIDLable:UILabel!
    //用户二维码
    var userQRView:UIImageView!

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setupViews()
    }
    func setupViews(){
        //用户头像
        userPic = UIImageView(frame: CGRect(x: 15, y: 10, width: 80, height: 80))
        self.contentView.addSubview(userPic)
        //用户名
        userNameLable = UILabel(frame: CGRect(x: 110, y: 15, width: 100, height: 30))
        self.contentView.addSubview(userNameLable)
        //用户帐号
        userIDLable = UILabel(frame: CGRect(x: 110, y: 55, width: kScreenWidth*0.6, height: 30))
        self.contentView.addSubview(userIDLable)
        //用户二维码
        userQRView = UIImageView(frame: CGRect(x: kScreenWidth*0.8, y: 30, width: 47, height: 47))
        self.contentView.addSubview(userQRView)

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
}

ChactsystemCell.swift代码如下:

import UIKit

class ChactsystemCell: UITableViewCell {
    //图片
    var iconView:UIImageView!
    //说明
    var infoLable:UILabel!

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setupViews()
    }
    //cell高50
    func setupViews(){
        //图片
        iconView = UIImageView(frame: CGRect(x: 15, y: 10, width: 30, height: 30))
        self.contentView.addSubview(iconView)
        //说明
        infoLable = UILabel(frame: CGRect(x: 55, y: 10, width: 100, height: 30))
        self.contentView.addSubview(infoLable)

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,692评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,482评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,995评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,223评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,245评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,208评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,091评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,929评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,346评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,570评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,739评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,437评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,037评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,677评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,833评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,760评论 2 369
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,647评论 2 354

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,095评论 4 62
  • 搁在以前,你问我最大的体育爱好是什么,我肯定是一本正经的告诉你:跑步。因为除了跑步,我没有试过其他的。我说我...
    小琴调阅读 541评论 2 3
  • 昨天爸爸的朋友送了一台跑步机,回家看到它我高兴坏了,终于梦想成真啦!以后可以在家跑步了,兴奋的我刚一到家就...
    独自的絮阅读 163评论 0 1
  • 点击↑↑↑↑【关注】按钮,就可自动接收每日更新内容
    爆漫画阅读 632评论 1 18