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


相关推荐

  • eMule 站点收集[通俗易懂]

    eMule 站点收集[通俗易懂]http://www.simplecd.org/http://qvocd.com/http://www.ied2k.com/http://www.thshare.net/http://www.eastgame.nethttp://www.chnp2p.com/http://www.hatrix.org/http://www.emule-ed2k.com/htt…

    2022年7月15日
    19
  • 笔记本卡顿不流畅是什么原因_笔记本卡顿不流畅是什么原因_笔记本电脑卡顿不流畅如何解决-win7之家…「建议收藏」

    笔记本卡顿不流畅是什么原因_笔记本卡顿不流畅是什么原因_笔记本电脑卡顿不流畅如何解决-win7之家…「建议收藏」有不少笔记本电脑用户在使用过程中,发现会经常会遇到卡顿不流畅的情况,很多用户不知道是什么原因引起的,其实原因有很多,可能是电脑本身配置不足,或者电脑占用率过高,或者内存不足等,接下来给大家带来笔记本电脑卡顿不流畅的详细解决方法吧。具体步骤如下:1、CPU不足电脑卡顿很多时候都是因为CPU占用过高,实质还是CPU太小引起的,我们可以将多余的进程或者软件关闭,或者更换性能好的CPU来解决这个问题,电脑…

    2025年10月30日
    6
  • 主、外键约束_创建主键约束

    主、外键约束_创建主键约束主、外键约束点关注不迷路,欢迎再来!主键和外键是两种类型的约束;1.主键是能唯一的标识表中的每一行,就是说这一列非空且值不重复,可以指定为主键;作用是用来强制约束表中的每一行数据的唯一性;2.外键是b表中的某一列引用的值来源于a表中的主键列。也是约束b表中的外键列的值必须取致a表中的主键列值,不是其中的值就不能插入b表中。可以形成a表b表的联系,保持数据的约束和关联性。创建主表主键…

    2022年10月20日
    3
  • Python模块-random模块[通俗易懂]

    Python模块-random模块

    2022年3月13日
    158
  • C#textBox变成密码框

    C#textBox变成密码框这不能说是技术了,也不能说是经验了,只能是提醒了。写C#基本都是用vs写吧,那在textBox对应的属性窗口里,有一个PasswordChar的属性,只要设置了对应的字符,那么textBox就成了密码框了。就是这么简单,浮云啊~

    2022年7月18日
    16
  • 机器学习中常见的过拟合解决方法

    机器学习中常见的过拟合解决方法在机器学习中,我们将模型在训练集上的误差称之为训练误差,又称之为经验误差,在新的数据集(比如测试集)上的误差称之为泛化误差,泛化误差也可以说是模型在总体样本上的误差。对于一个好的模型应该是经验误差约等

    2022年8月5日
    5

发表回复

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

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