//建立UISegmentedControl的数组

NSArray *segmentedArray = [NSArray arrayWithObjects:@"线下培训",@"在线培训",@"模拟面试",@"Marlin面试",nil];

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];

//设置样式 当为Bordered和Bar时tintColor才有效

segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

segmentedControl.tintColor = [UIColor clearColor];

//    文字选中的颜色

[segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:39/255.0 green:193/255.0 blue:180/255.0 alpha:1.0f]} forState:UIControlStateSelected];

//   文字未选中的颜色

[segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];

//背景未选中的颜色

[segmentedControl setBackgroundImage:[WTImage imageWithColor:[UIColor colorWithRed:39/255.0 green:193/255.0 blue:180/255.0 alpha:1.0f] size:CGSizeMake(WIDTH, 44) alpha:1] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

//背景选中的颜色

[segmentedControl setBackgroundImage:[WTImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(WIDTH, 44) alpha:1] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

//设置圆角

segmentedControl.layer.cornerRadius = 4;

segmentedControl.clipsToBounds = YES;

//设置frame

  segmentedControl.frame = CGRectMake(0.0, 0.0, 290, 30.0);

//设置默认选中的index

segmentedControl.selectedSegmentIndex = 0;

[segmentedControl addTarget:self  action:@selector(indexDidChangeForSegmentedControl:)

forControlEvents:UIControlEventValueChanged];

//方法1

//[self.navigationController.navigationBar.topItem setTitleView:segmentedControl];

//方法2

[self.navigationItem setTitleView:segmentedControl];

//segmentedControl选中方法

-(void)indexDidChangeForSegmentedControl:(UISegmentedControl *)Seg{

NSInteger Index = Seg.selectedSegmentIndex;

NSLog(@"Index %i", Index);

switch (Index) {

case 0:

[self selectmyView1];

NSLog(@"%li",(long)Index);

break;

case 1:

[self selectmyView2];

NSLog(@"%li",(long)Index);

break;

case 2:

[self selectmyView3];

NSLog(@"%li",(long)Index);

break;

case 3:

[self selectmyView4];

NSLog(@"%li",(long)Index);

break;

default:

break;

}

}

UISegmentedControl-iOS的更多相关文章

  1. iOS - UISegmentedControl

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UISegmentedControl : UIControl <NSCoding> @available ...

  2. 【IOS 开发】基本 UI 控件详解 (UISegmentedControl | UIImageView | UIProgressView | UISlider | UIAlertView )

    转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50163725 一. 分段控件 (UISegmentedControl) 控件展 ...

  3. iOS开发之七:常用控件--UISlider、UISegmentedControl、UIPageControl的使用

    一.UISlider的使用 其实UISlider在iOS开发中用的似乎不是很多,我们看到的用到的地方多是音乐播放器的音量控制,以及视频播放器中的音量控制. 还是记录一下吧! 1.常用属性 // 设置获 ...

  4. RadioGroup实现类似ios的分段选择(UISegmentedControl)控件

    在ios7中有一种扁平风格的控件叫做分段选择控件UISegmentedControl,控件分为一排,横放着几个被简单线条隔开的按钮,每次点击只能选择其中一个按钮,他类似于tabbar但是又稍微有点区别 ...

  5. UISegmentedControl字体大小,颜色,选中颜色,左边椭圆,右边直线的Button 解决之iOS开发之分段控制器UISegmentedControl

        NSArray *segmentedArray = [NSArrayarrayWithObjects:STR(@"Mynews"),STR(@"Systemmes ...

  6. iOS开发之分段控制器(UISegmentedControl)

    今天我们来说下iOS中的分段选择控制器UISegmentedControl,这一控件有什么作用呢 每个segment都能被点击,相当于集成了多个button 通常我们会点击不同的segment来切换不 ...

  7. ios UISegmentedControl的使用简介

    初始化UISegmentedControl NSArray *arr = [[NSArray alloc]initWithObjects:@"轻拍",@"长按" ...

  8. iOS在导航栏上居中显示分段控件(UISegmentedControl)

    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil]; segmentedCont ...

  9. IOS UI segmentedControl UISegmentedControl 常见属性和用法

    UISegmentedControl中一些常见的属性和用法 //设置以图案作为分段的显示,仅需要图案的轮廓,这样颜色为分段的背景颜色 //    NSArray *items = @[[UIImage ...

  10. IOS 7 Study - UISegmentedControl

    You would like to present a few options to your users from which they can pick anoption, through a U ...

随机推荐

  1. Linux系统在启动过程中grub引导文件丢失的解决方法

    在/boot/grub2目录下有一个grub.cfg文件:该文件主要是用来自动地引导系统启动内核程序和系统的初始化程序. 问题一:当系统在启动的情况下,我们不小心删除/boot/grub2/grub. ...

  2. java.sql.SQLException: Unsupported character encoding 'utf8mb4'.

    四月 12, 2017 3:47:52 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() fo ...

  3. HDU 1452

    http://acm.hdu.edu.cn/showproblem.php?pid=1452 原来真心没见过这种题,不会做,非常帅 gcd(a,b)==1 && s(a,b)==s(a ...

  4. 用python验证蒙提霍尔问题

    最初看到这个问题是初中的时候买了一本有关数学谜题的书里面概率论的一张的课后拓展就是说到三门问题,当时作为一个扩展阅读看了一下,里面说到了一个世界智商最高的女人秒杀了美国一大群的数学高材生的精彩故事(比 ...

  5. Spring 管理Filter和Servlet

    本文转载自:http://www.open-open.com/lib/view/open1417248512252.html 在使用spring容器的web应用中,业务对象间的依赖关系都可以用cont ...

  6. JanusGraph Server配置

    转自:https://www.cnblogs.com/jiyuqi/p/320267ff0b5052fad4613945e58ea1f1.html JanusGraph使用Gremlin Server ...

  7. LeetCode My Calendar I

    原题链接在这里:https://leetcode.com/problems/my-calendar-i/description/ 题目: Implement a MyCalendar class to ...

  8. smarty基本用法,循环,判断

    require './smarty/Smarty.class.php'; $sm = new Smarty; $sm->setTemplateDir("./dir");//设 ...

  9. arm_linux QT+v4l 显示视频

    1.参考(原创)基于ZedBoard的Webcam设计(三):视频的采集和动态显示 下载代码实测可用. 2.重新下载了csdn的代码,缺widget.h文件,后重新生成widget工程(自动产生wid ...

  10. 【转载】CreateThread与_beginthreadex本质区别

    转载文章,原文地址:http://blog.csdn.net/morewindows/article/details/7421759 本文将带领你与多线程作第一次亲密接触,并深入分析CreateThr ...