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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • “仅三天可见” 的朋友圈有方法破解啦!

    “仅三天可见” 的朋友圈有方法破解啦!点击上方“逆锋起笔”,公众号回复PDF领取大佬们推荐的学习资料之前微博上出现过一个热搜话题:超一亿人朋友圈仅三天可见。微信创始人张小龙在年度演讲里说,这个开关,是微信里使用最多的。很多…

    2022年6月13日
    52
  • mysql != 索引_Mysql语法

    mysql != 索引_Mysql语法转:https://www.cnblogs.com/huanzi-qch/p/15238604.html介绍通常情况下,全文检索引擎我们一般会用ES组件(传送门:SpringBoot系列——ElasticSearch),但不是所有业务都有那么大的数据量、那么大的并发要求,MySQL5.7之后内置了ngram分词器,支持中文分词,使用全文索引,即可实现对中文语义分词检索MySQL支持全文索引和搜索:  MySQL中的全文索引是FULLTEXT类型的索引。  全文索引只能用于InnoDB或My

    2022年8月24日
    21
  • wpf listview 分组_JAVA排序

    wpf listview 分组_JAVA排序网上很多方法,但是内容包含太全面,代码看上去很复杂,其实其中有很多是控制UI的,此种方法一行代码自动解决排序问题,另外,wpf的listview和winform的listview细节差别还是很多的。在WPF中ListView的排序最基本的原理很简单就一句话ListViewControl.Items.SortDescriptions.Add(newSortDescription(“name”,…

    2022年10月3日
    0
  • 怎么修改HTML网页的名字_如何修改html文件内容

    怎么修改HTML网页的名字_如何修改html文件内容NetCms默认设置中,只能上传Doc文件,不能上传xls文件和PPT文件。 上传文件类型可以“控制面板–>参数设置–>上传文件允许格式”中设置。但是,仅能上传,添加新闻时,添加附件的文件选择框中无法看到xls文件和ppt文件。 通过查看源文件,添加新闻页面是~/Manage/News/News_add.aspx文件,在该文件中,添加附件位置,通过调用JavaScript的s

    2022年9月29日
    0
  • 【Redis】五种数据类型及其使用场景

    Redis数据类型五种类型与类比java的模型string–>Stringhash–>Hashmaplist–>LinkListset–>HashSetsorted_set–>TreeSetString类型redis数据存储格式redis自身是一个Map类型的存储方式,其中所有的数据都是采用key:value的形式存储我们讨论的数据类型指的是存储的数据的类型,也就是value部分的类型,key部分永远都是字符串St

    2022年4月9日
    74
  • icem划分网格步骤_ICEM CFD教程-icem网格划分教程

    icem划分网格步骤_ICEM CFD教程-icem网格划分教程ICEMCFD教程四面体网格对于复杂外形,ICEMCFDTetra具有如下优点:根据用户事先规定一些关键的点和曲线基于8叉树算法的网格生成,生成速度快,大约为1500cells/second无需表面的三角形划分,直接生成体网格四面体网格能够合并到混合网格中,并实施平滑操作单独区域的粗化和细化ICEMCFD的CAD(CATIAV4,UG,ProE,IGES,andP…

    2022年5月9日
    44

发表回复

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

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