无标题文章

//每一个被导航视图控制器所管理的视图控制器都有一个navigationItem(这里面包含了左按钮,右按钮,中间标题,中间视图)

//设置导航栏的标题

navigationItem.title="Setting"

letleftBarBtn =UIBarButtonItem(barButtonSystemItem: .Camera, target:self, action:"leftBtnAction")

//设置右边按钮

letrightBarBtn =UIBarButtonItem(title:"next", style:UIBarButtonItemStyle.Plain, target:self, action:"rightBtnAction")

//设置导航栏左按钮leftBarButtonItem:(UIBarButtonItem)

navigationItem.leftBarButtonItem= leftBarBtn

navigationItem.rightBarButtonItem= rightBarBtn

//设置左右item数组

//navigationItem.leftBarButtonItems = [leftBarBtn,rightBarBtn]

//navigationItem.rightBarButtonItems = [leftBarBtn,rightBarBtn]

//设置中间视图

letsegment =UISegmentedControl(items: ["已接来电","未接来dian"])

segment.frame=CGRectMake(0,0,100,30)

segment.selectedSegmentIndex=1

//设置中间视图

navigationItem.titleView= segment

//导航栏(UINavigationBar)

//在本类中(视图控制器)访问navigationController就是获取到本视图控制器所在的导航视图控制器

//设置导航栏是否隐藏

navigationController?.navigationBarHidden=false

//设置导航栏样式

navigationController?.navigationBar.barStyle= .Default

//背景颜色

navigationController?.navigationBar.backgroundColor=UIColor.cyanColor()

//导航栏本身的颜色

navigationController?.navigationBar.barTintColor=UIColor.yellowColor()

//导航栏元素颜色(左按钮,右按钮.........)

navigationController?.navigationBar.tintColor=UIColor.redColor()

//导航栏半透明效果

navigationController?.navigationBar.translucent=false

letmyView =UIView(frame:CGRectMake(0,0,150,150))

myView.backgroundColor=UIColor.blueColor()

view.addSubview(myView)

//navigationController的contentView显示的谁的View?

}

//跳转第二个控制器页面

funcrightBtnAction(){

//(1)创建第二个控制器

letsecondVC =SecondViewController()

//(2)使用当前控制器所在的导航视图控制器跳转到第二个控制器pushViewController(进入到下一个页面)

navigationController?.pushViewController(secondVC, animated:true)

}

funcleftBtnAction(){

print("click left Btn")

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}


overridefuncviewDidLoad() {

super.viewDidLoad()

//设置页面颜色为白色

view.backgroundColor=UIColor.whiteColor()

//设置标题

navigationItem.title="SecondVC"

letleftBarBtn =UIBarButtonItem(title:"back", style:UIBarButtonItemStyle.Plain, target:self, action:"backAction:")

navigationItem.leftBarButtonItem= leftBarBtn

letrightBtn =UIBarButtonItem(title:"进入3", style:UIBarButtonItemStyle.Plain, target:self, action:"pushToThirdVC")

navigationItem.rightBarButtonItem= rightBtn

}

funcpushToThirdVC(){

letthirdVC =ThirdViewController()

navigationController?.pushViewController(thirdVC, animated:true)

}

funcbackAction(btn:UIBarButtonItem){

print("返回")

//将SecondVc出棧popViewControllerAnimated:将当前显示在棧顶的控制器出棧(回到上一个页面)

navigationController?.popViewControllerAnimated(true)

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}


overridefuncviewDidLoad() {

super.viewDidLoad()

navigationItem.title="thirdVC"

letrightBtn =UIBarButtonItem(title:"进入4", style:UIBarButtonItemStyle.Plain, target:self, action:"pushToFourthVC")

navigationItem.rightBarButtonItem= rightBtn

}

funcpushToFourthVC(){

letfourthVC =FourthViewController()

navigationController?.pushViewController(fourthVC, animated:true)

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

你可能感兴趣的:(无标题文章)