zoukankan      html  css  js  c++  java
  • 【开发笔记】 UISegmentedController 控件使用

    效果图:

    代码:

        NSArray *segmentTextContent = [NSArray arrayWithObjects: @"Check", @"Search", @"Tools", nil];
        UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
        
        CGRect frame = CGRectMake(50, 100,self.view.bounds.size.width - (50 * 2.0),40);
        segmentedControl.frame = frame;
        [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
        segmentedControl.selectedSegmentIndex = 1;
        
        [self.view addSubview:segmentedControl];
        [segmentedControl release];

    2.UISegmentedControl 放在 UIToolBar上面

    效果图:

    代码:

      NSArray *array = @[@"列表",@"",@""];
        UISegmentedControl *modePicker = [[UISegmentedControl alloc]initWithItems:array];
        modePicker.segmentedControlStyle = UISegmentedControlStyleBar; 
        
        [modePicker setWidth:50 forSegmentAtIndex:0]; 
        [modePicker setWidth:50 forSegmentAtIndex:1];
        [modePicker setWidth:50 forSegmentAtIndex:2];
        
        NSString *todayTitle = @"今天";
        UIBarButtonItem *todayButton = [[UIBarButtonItem alloc] initWithTitle:todayTitle style:UIBarButtonItemStyleBordered target:self action:@selector(todayButtonTapped:)];
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:modePicker];
      [modePicker release]
      UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; [fixedSpace setWidth:20];
    [self setToolbarItems:@[todayButton, fixedSpace, item] animated:NO];
      [[self navigationController] setToolbarHidden:NO animated:NO];

      [todayButton release];
      [item release];
      [fixedSpace release];
  • 相关阅读:
    【3.1】学习C++之再逢const
    【8】学习C++之this指针
    【7】学习C++之类的构造函数
    【6】学习C++之类的实例化及访问
    【5】学习C++之类的概念
    【4】学习C++之内存管理
    【3】学习C++之const关键字的使用
    【2】学习C++之引用
    【C#第一天】数据相关
    【1】学习C++时,一些零散知识点01
  • 原文地址:https://www.cnblogs.com/zeejun/p/3089623.html
Copyright © 2011-2022 走看看