iOS 分度那控制UISegmentedControl添加到导航栏上的使用方法
来源:互联网 发布:python 量化平台 编辑:程序博客网 时间:2024/05/17 02:43
//
// RootViewController.m
// Segement
//
// Created by ancun on 14/9/4.
// Copyright (c) 2015年 ancun. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()
{
UIView *_aview;
}
@end
@implementation RootViewController
-(void)viewWillAppear:(BOOL)animated
{
[superviewWillAppear:animated];
self.navigationController.navigationBarHidden =NO;
self.navigationController.navigationBar.translucent = NO;
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColorgrayColor];
UISegmentedControl *segment = [[UISegmentedControlalloc]initWithItems:@[@"红",@"黄",@"蓝",@"绿"]];
segment.frame =CGRectMake(60,100,200,40);
self.navigationItem.titleView = segment;
// [self.view addSubview:segment];
//[segment setTitle:@"nv" forSegmentAtIndex:2];//修改
[segment insertSegmentWithTitle:@"hei"atIndex:4animated:YES];//添加一个分段
segment.selectedSegmentIndex =1;//选择按下标
segment.momentary =NO;//点完以后会起来,按钮(瞬间选中离开)默认为NO
[segment setEnabled:NOforSegmentAtIndex:3];//不能使用的按钮(灰色)
segment.tintColor=[UIColorredColor];
//[dubai]分度添加响应方式
[segment addTarget:selfaction:@selector(handelSegementControlAction:)forControlEvents:(UIControlEventValueChanged)];
//[dubai]添加一个视图
_aview = [[UIViewalloc]initWithFrame:CGRectMake(60,200,200,200)];
_aview.backgroundColor = [UIColorwhiteColor];
[self.viewaddSubview:_aview];
}
//[dubai]点击分段控制执行相应的方法
- (void)handelSegementControlAction:(UISegmentedControl *)segment
{
NSLog(@"%s",__FUNCTION__);
switch (segment.selectedSegmentIndex) {
case0:
{
_aview.backgroundColor = [UIColorredColor];
break;
}
case1:
{
_aview.backgroundColor = [UIColor yellowColor];
break;
}
case2:
{
_aview.backgroundColor = [UIColor blueColor];
break;
}
case3:
{
_aview.backgroundColor = [UIColor greenColor];
break;
}
default:
{
_aview.backgroundColor = [UIColor blackColor];
break;
}
break;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
- iOS 分度那控制UISegmentedControl添加到导航栏上的使用方法
- iOS 导航条上添加UISegmentedControl,点击分类按钮,显示不同的ViewController
- IOS在导航栏上居中显示分段控件(UISegmentedControl)
- IOS在导航栏上居中显示分段控件(UISegmentedControl)
- iOS--UISegmentedControl的使用方法详细
- 在UINavigationController的导航栏中添加UISegmentedControl
- 在UINavigationController的导航栏中添加UISegmentedControl
- 在导航栏中添加UISegmentedControl
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- iOS-导航栏的使用方法
- IOS导航栏的使用方法
- IOS导航栏的使用方法
- 利用 onload 事件监控跨站资源
- js刷新页面方法大全
- CSS3开发工具收集
- CTR评估标准及ROC与AUC
- android的application总结
- iOS 分度那控制UISegmentedControl添加到导航栏上的使用方法
- 【J2SE快速进阶】——Java多线程机制
- [读书笔记]iOS与OS X多线程和内存管理 [Blocks部分-3]
- mysql数据库优化3
- Sql竖转横
- ppt转换为pdf详解教程
- 五个程序员求职者的最佳提问
- x64平台下VC++中汇编函数的编写问题
- VisionMobile:开发者经济报告 2015年Q1:开发者国度状况(一)关键提要