zoukankan      html  css  js  c++  java
  • 在UIBarButtonItem上添加UISegmentedControl

    在导航栏中加上分段控件是很常用的做法,效果如下:

    UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 8.0f, 300.0f, 30.0f) ]; 
    [segmentedControl insertSegmentWithTitle:@"最新上架" atIndex:0 animated:YES];
    [segmentedControl insertSegmentWithTitle:@"热销商品" atIndex:1 animated:YES];
    [segmentedControl insertSegmentWithTitle:@"促销商品" atIndex:2 animated:YES];
    //[segmentedControl insertSegmentWithImage:[UIImageimageNamed:@"style12"] atIndex:0animated:YES];


    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    //segmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;
    segmentedControl.momentary = YES;
    segmentedControl.multipleTouchEnabled=NO;
    //segmentedControl.userInteractionEnabled=YES;
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    //segmentedControl.tintColor=[UIColor clearColor];

    UIBarButtonItem *homeBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
    self.navigationItem.rightBarButtonItem = homeBarItem;

    对应的方法:

    -(void)segmentAction:(UISegmentedControl *)Segment{
    NSInteger index = Segment.selectedSegmentIndex;

    if (index == 0) {
    //最新上架
    NewestGoods *newestGoods = [[NewestGoods alloc] initWithNibName:@"NewestGoods" bundle:nil];
    newestGoods.navigationItem.title = @"最新上架";
    [self.navigationController pushViewController:newestGoods animated:YES];
    }else if (index == 1) {
    //热销商品
    HotItems *hotItems = [[HotItems alloc] initWithNibName:@"HotItems" bundle:nil];
    hotItems.navigationItem.title = @"热销商品";
    [self.navigationController pushViewController:hotItems animated:YES];
    }else {
    //促销商品
    PromotionsGoods *promotionsGoods = [[PromotionsGoods alloc] initWithNibName:@"PromotionsGoods" bundle:nil];
    promotionsGoods.navigationItem.title = @"促销商品";
    [self.navigationController pushViewController:promotionsGoods animated:YES];
    }


    }




  • 相关阅读:
    习题4.7利用vector实现数据复制
    习题4.18
    4.8编写一小段程序实现两vector是否相等的比较
    关于野指针
    学习c++的50条忠告
    c++头文件
    习题4.14
    容器和迭代器
    Android上C++对象的自动回收机制分析
    Windows下载Android源码
  • 原文地址:https://www.cnblogs.com/foxmin/p/2434459.html
Copyright © 2011-2022 走看看