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];
    }


    }




  • 相关阅读:
    Node.js :HTTP请求和响应流程
    Node.js :URL、QueryString介绍
    jQuery
    如何angular过滤器进行排序???
    封装jsonp
    原生js的math对象
    Iscrool下拉刷新
    javascript闭包
    javascript对象(3)
    javascript对象(2)
  • 原文地址:https://www.cnblogs.com/foxmin/p/2434459.html
Copyright © 2011-2022 走看看