swift 它们的定义TabBarItem

swift 它们的定义TabBarItem

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

swift 它们的定义TabBarItem1.效果图


swift 它们的定义TabBarItem   
swift 它们的定义TabBarItem


2.NewsViewController.swift


//
//  NewsViewController.swift
//  NavigationDemo
//
//  Created by 赵超 on 14-6-27.
//  Copyright (c) 2014年 赵超. All rights reserved.
//

import UIKit

class NewsViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor=UIColor.blueColor()
        self.title="新闻"
    }
}

3.MoviewViewController.swift

//
//  MovieViewController.swift
//  NavigationDemo
//
//  Created by 赵超 on 14-6-27.
//  Copyright (c) 2014年 赵超. All rights reserved.
//

import UIKit

class MovieViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor=UIColor.redColor()
        self.title="电影"
    }
}

4.AppDelegate.swift

//
//  AppDelegate.swift
//  NavigationDemo
//
//  Created by 赵超 on 14-6-27.
//  Copyright (c) 2014年 赵超. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
                            
    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        // Override point for customization after application launch.
        self.window!.backgroundColor = UIColor.whiteColor()
        self.window!.makeKeyAndVisible()
        //设置根控制器
        var root=RootViewController()
        self.window!.rootViewController=root
        return true
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

5.RootViewController.swift

//
//  RootViewController.swift
//  NavigationDemo
//
//  Created by 赵超 on 14-6-27.
//  Copyright (c) 2014年 赵超. All rights reserved.
//å

import UIKit

class RootViewController: UITabBarController {

    var tabBarBgImg:UIImageView?

var tabBarBgImgSelected:UIImageView? override func viewDidLoad() { super.viewDidLoad() //隐藏自带tabBarItem self.tabBar.hidden=true customTabBar() loadViewController() } //选择视图 func test(tap:UITapGestureRecognizer){ var view=tap.view var index=view.tag as Int var z=(index)*57 var c=CGFloat(z) var x:CGFloat=5.0 + c var y=tabBarBgImg!.frame.size.height/2-45/2 UIView.beginAnimations("test",context:nil) tabBarBgImgSelected!.frame = CGRectMake(x ,y, 50, 45) UIView.commitAnimations() //跳转页面 self.selectedIndex=view.tag } //自己定义tabBar视图 func customTabBar(){ var height=UIScreen.mainScreen().bounds.size.height var width=UIScreen.mainScreen().bounds.size.width var tabW=width var tabH=height-49 tabBarBgImg=UIImageView(frame:CGRectMake(0,tabH,tabW,49)) //打开事件 tabBarBgImg!.userInteractionEnabled=true tabBarBgImg!.image=UIImage(named:"tab_bg_all") //选中背影图片 var y=tabBarBgImg!.frame.size.height/2-45/2 tabBarBgImgSelected=UIImageView(frame:CGRectMake(5,y, 50, 45)) tabBarBgImgSelected!.image=UIImage(named:"selectTabbar_bg_all1") tabBarBgImg!.addSubview(tabBarBgImgSelected) var x:CGFloat=0 var images=["icon_cinema","msg_new"] var titles=["电影","新闻"] var titleFont=UIFont.systemFontOfSize(12) for index in 0..2{ var imgView=UIImageView(frame:CGRectMake( x+18, y+5, 22, 22)) //加入事件 imgView.userInteractionEnabled=true imgView.tag=index var tap=UITapGestureRecognizer(target:self,action:Selector("test:")) imgView.addGestureRecognizer(tap) imgView.image = UIImage(named:images[index]) tabBarBgImg!.addSubview(imgView) var title=UILabel(frame:CGRectMake(x+16,y+26,45,15)) title.text=titles[index] title.font=titleFont title.textColor = UIColor.whiteColor() tabBarBgImg!.addSubview(title) x+=57 } self.view.addSubview(tabBarBgImg) } //载入子视图控制器 func loadViewController(){ //USA var movie=MovieViewController() var movieItem=UITabBarItem(tabBarSystemItem: .Favorites,tag:1) movie.tabBarItem=movieItem var movieNav=UINavigationController(rootViewController:movie) //News var news=NewsViewController() var newsItem=UITabBarItem(tabBarSystemItem: .Favorites,tag:2) news.tabBarItem=newsItem var newsNav=UINavigationController(rootViewController:news) //数组 var ctrls=[movieNav,newsNav] //加入 self.setViewControllers(ctrls,animated:true) } }

版权声明:本文博主原创文章,博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117103.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 初识java——hello world(代码讲解很详细)[通俗易懂]

    初识java——hello world(代码讲解很详细)[通俗易懂]在每学一门语言之前我们首先要学会helloworld的的写法,下面我用java写了一个hello的输出以及每行代码的讲解;publicclasshelloworld{publicstaticvoidmain(String[]args){System.out.println(“helloworld!”);System.out.printf(“helloworld!!\n”);System.out.print(“hellow

    2022年5月28日
    203
  • qmake介绍

    qmake介绍文章目录简单介绍下qmake简要介绍关于pro文件构建一个项目使用第三方库预编译头文件让我们开始试试吧从一个简单的例子开始允许程序可以Debug添加特定平台的源文件设置当文件不存在的时候就停止qmake检查多个条件qmake可以帮助我们在跨平台构建应用程序的时候变得更简单,我们可以通过写简单的几行必要的信息来生成构建文件,我们可以在任何的软件项目中使用qmakeqmake基于pro文件生产构建…

    2022年5月19日
    87
  • smalldatetime和datetime的差别

    smalldatetime和datetime的差别碰上了这件事,才学到教训,一直以为smalldatetime和datetime的差别只是在于时间范围:smalldatetime的有效时间范围1900/1/1~2079/6/6datetime的有效时间范围1753/1/1~9999/12/31所以我判断如果该值不用到太远的日期范围,就会使用smalldatetime。但我忽略了更关键的差别,那就是smalldatetime只精准到分,而datet…

    2022年5月19日
    32
  • git删除远程分支

    1.git删除远程分支gitpushorigin–delete[branch_name]2.删除本地分支区别gitbranch-d会在删除前检查merge状态(其与上游分支或者与head)。gitbranch-D是gitbranch–delete–force的简写,它会直接删除。共同点都是删除本地分支的方法(与删除远程分支命令相独立,要想本地和远程都删除,必须得运行两个命令)。3.git查看分支:查看本地分支gitbranch查看远程分支

    2022年4月3日
    94
  • Java异或什么意思_0与0异或

    Java异或什么意思_0与0异或异或^的几个作用一、交换两个整数的值而不必用第三个参数a=9;b=11;a=a^b;1001^1011=0010b=b^a;1011^0010=1001a=a^b;0010^1001=1011a=11;b=9;二、奇偶判断^a操作就是将a中的每一位按位逐一进行异或,例如a=4’b1010,则b=1^0^1^0=0,由此可以判断a中为1的位数是奇数还是偶数,是一个便捷的操作。三、格雷码(Graycode)格雷码(Graycode)是由贝…

    2022年10月4日
    4
  • 虚拟机和宿主机共享文件_安装vmware的宿主机

    虚拟机和宿主机共享文件_安装vmware的宿主机虚拟机网络共享给宿主机宿主机使用虚拟机的VPN连接需求VMware虚拟机中跑Windows10(下文称Guest),使用某客户端连接公司VPN(还需要启动联软UniAccess才可以正常访问内网),宿主机为Windows10(下文称Host),未安装该VPN客户端。现需要在Guest中连接VPN,然后共享给Host使用。关键词桥接:对应虚拟网卡VMnet0仅主机模式(HostOnly):对应虚拟网卡VMnet1实现步骤1.Guest添加桥接网卡

    2022年8月20日
    9

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号