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


    }




  • 相关阅读:
    mysql数据库主从同步复制原理
    NoSQL
    Mysqldump参数大全
    MySQL Show命令的使用
    学习shell脚本之前的基础知识
    详解MySQL大表优化方案
    sql索引的优缺点
    [C#] 取得每月第一天和最後一天、某月总天数
    Easy ui DateBox 控件格式化显示操作
    StudioStyle 使用 厌倦了默认的Visutal Studio样式了,到这里找一个酷的试试
  • 原文地址:https://www.cnblogs.com/foxmin/p/2434459.html
Copyright © 2011-2022 走看看