当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS展开三级列表效果示例

IOS展开三级列表效果示例

2019年07月24日  | 移动技术网移动技术  | 我要评论

效果图如下:

#import <uikit/uikit.h>

@interface appdelegate : uiresponder <uiapplicationdelegate>

@property (strong, nonatomic) uiwindow *window;


@end
#import "appdelegate.h"
#import "rootviewcontroller.h"
@interface appdelegate ()

@end

@implementation appdelegate


- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
  self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
  // override point for customization after application launch.
  self.window.backgroundcolor = [uicolor whitecolor];
  
  rootviewcontroller *root = [[rootviewcontroller alloc] init];
  uinavigationcontroller *navi = [[uinavigationcontroller alloc] initwithrootviewcontroller:root];
  self.window.rootviewcontroller = navi;
  
  [self.window makekeyandvisible];
  return yes;
}


@end
#import <uikit/uikit.h>
 
@interface rootviewcontroller : uiviewcontroller
 
@end
#import "rootviewcontroller.h"
#import "maincell.h"
#import "detialtableviewcell.h"
@interface rootviewcontroller ()<uitableviewdatasource,uitableviewdelegate>
{
  uitableview *_tableview;
  nsmutabledictionary *dic;//存对应的数据
  nsmutablearray *selectedarr;// 二级列表是否展开状态
  nsmutablearray *titledataarray;
  nsarray *dataarray;//数据源,显示每个cell的数据
  nsmutabledictionary *statedic;//三级列表是否展开状态
  nsmutablearray *grouparr0;
  nsmutablearray *grouparr1;
  nsmutablearray *grouparr2;
  nsmutablearray *grouparr3;
  nsmutablearray *grouparr4;
  nsmutablearray *grouparr5;
  
}
@end

@implementation rootviewcontroller

- (void)viewdidload {
  [super viewdidload];
  self.title = @"列表";
  dic = [[nsmutabledictionary alloc] init];
  selectedarr = [[nsmutablearray alloc] init];
  dataarray = [[nsmutablearray alloc] init];
  
  // 初始化tableview
  _tableview = [[uitableview alloc] initwithframe:cgrectmake(0, 0, 320*scalex, [uiscreen mainscreen].bounds.size.height) style:uitableviewstyleplain];
  _tableview.delegate = self;
  _tableview.datasource = self;
  // 隐藏滚动条
  _tableview.showsverticalscrollindicator = no;
  _tableview.showshorizontalscrollindicator = no;
  _tableview.separatorstyle = uitableviewcellseparatorstylenone;
  [self.view addsubview:_tableview];
  
  // 加载数据
  [self loaddata];
}
/**
 * 加载数据
 */
- (void)loaddata
{
  titledataarray = [[nsmutablearray alloc] initwithobjects:@"亲朋",@"家人",@"好友", @"蓝颜",@"同学",@"老乡",nil];
  
  nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"小莉",@"name",@"no",@"state", nil];
  nsmutabledictionary *nameandstatedic2 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"婷婷",@"name",@"no",@"state", nil];
  nsmutabledictionary *nameandstatedic3 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"小庄",@"name",@"no",@"state", nil];
  
  grouparr0 = [[nsmutablearray alloc] initwithobjects:nameandstatedic1,nameandstatedic2,nameandstatedic3, nil];
  
  nsmutabledictionary *nameandstatedic4 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"晨晨姐",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic5 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"李涛",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic6 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"海波",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic7 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"张敏",@"name",@"no",@"state",nil];
  
  grouparr1 = [[nsmutablearray alloc]initwithobjects:nameandstatedic4,nameandstatedic5,nameandstatedic6,nameandstatedic7, nil];
  
  nsmutabledictionary *nameandstatedic8 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"杨浩",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic9 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"小明",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic10 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"洋洋",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic11 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"赵蒙",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic12 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"小催",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic13 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"和平",@"name",@"no",@"state",nil];
  
  grouparr2 = [[nsmutablearray alloc]initwithobjects:nameandstatedic8,nameandstatedic9,nameandstatedic10,nameandstatedic11,nameandstatedic12,nameandstatedic13,nil];
  
  nsmutabledictionary *nameandstatedic14 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"超人",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic15 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"怪兽",@"name",@"no",@"state",nil];
  
  grouparr3 = [[nsmutablearray alloc] initwithobjects:nameandstatedic14,nameandstatedic15, nil];
  
  nsmutabledictionary *nameandstatedic16 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"大包",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic17 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"小林子",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic18 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"石头",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic19 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"小轩轩",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic20 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"阿东",@"name",@"no",@"state",nil];
  
  grouparr4 = [[nsmutablearray alloc]initwithobjects:nameandstatedic16,nameandstatedic17,nameandstatedic18,nameandstatedic19,nameandstatedic20, nil];
  
  nsmutabledictionary *nameandstatedic21 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"郑平",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic22 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"刘凡",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic23 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"韩琴",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic24 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"刘华健",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic25 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"彭晓明",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic26 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"张欢",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic27 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"刘来楠",@"name",@"no",@"state",nil];
  nsmutabledictionary *nameandstatedic28 = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",@"任强",@"name",@"no",@"state",nil];
  
  grouparr5 = [[nsmutablearray alloc]initwithobjects:nameandstatedic21,nameandstatedic22,nameandstatedic23,nameandstatedic24,nameandstatedic25,nameandstatedic26,nameandstatedic27,nameandstatedic28, nil];

  [dic setvalue:grouparr0 forkey:@"0"];
  [dic setvalue:grouparr1 forkey:@"1"];
  [dic setvalue:grouparr2 forkey:@"2"];
  [dic setvalue:grouparr3 forkey:@"3"];
  [dic setvalue:grouparr4 forkey:@"4"];
  [dic setvalue:grouparr5 forkey:@"5"];
  
}

#pragma mark - tableviewdelegate - 
// 返回几个表头
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview
{
  return titledataarray.count;
}

// 每个表头返回几行
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section
{
  nsstring *string = [nsstring stringwithformat:@"%d",(int)section];
  // 如果表头返回值不为零,则修改图片(改成箭头向下的图片)
  if ([selectedarr containsobject:string]) {
    uiimageview *imageview = (uiimageview *)[_tableview viewwithtag:20000 + section];
    imageview.image = [uiimage imagenamed:@"buddy_header_arrow_down"];
    
    nsarray *array1 = dic[string];
    return array1.count;
  }
  return 0;
}

// 设置表头的高度
- (cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section
{
  return 40*scalex;
}
// section footer的高度
- (cgfloat)tableview:(uitableview *)tableview heightforfooterinsection:(nsinteger)section
{
  return 0.2;
}
// 设置view,将替代titleforheaderinsection方法
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section
{
  uiview *view = [[uiview alloc] initwithframe:cgrectmake(0, 0, 320*scalex, 30*scaley)];
  view.backgroundcolor = [uicolor whitecolor];
  
  uilabel *titlelabel = [[uilabel alloc] initwithframe:cgrectmake(20*scalex, 5*scaley, tableview.frame.size.width - 20*scalex, 30*scaley)];
  titlelabel.text = [titledataarray objectatindex:section];
  [view addsubview:titlelabel];
  
  uiimageview *imageview = [[uiimageview alloc] initwithframe:cgrectmake(5*scalex, 12*scaley, 15*scalex, 15*scaley)];
  imageview.tag = 20000+section;

  // 判断是不是选中状态
  nsstring *string = [nsstring stringwithformat:@"%d",(int)section];
  if ([selectedarr containsobject:string]) {
    imageview.image = [uiimage imagenamed:@"buddy_header_arrow_down"];
  }else{
    imageview.image = [uiimage imagenamed:@"buddy_header_arrow_right"];
  }
  [view addsubview:imageview];
  
  uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];
  button.frame = cgrectmake(0, 0, 320*scalex, 40*scaley);
  button.tag = 100 + section;
  [button addtarget:self action:@selector(buttonaction:) forcontrolevents:uicontroleventtouchupinside];
  [view addsubview:button];
  
  uiimageview *lineimage = [[uiimageview alloc] initwithframe:cgrectmake(0, 40*scaley - 1, 320*scalex, 1)];
  lineimage.image = [uiimage imagenamed:@"line"];
  [view addsubview:lineimage];
  
  return view;
}

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath
{
  nsstring *indexstr = [nsstring stringwithformat:@"%d",(int)indexpath.section];
  if ([dic[indexstr][indexpath.row][@"cell"] isequaltostring:@"maincell"]) {
    return 60*scaley;
  }else{
    return 40*scaley;
  }
}

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
{
  // 当前是第几个表头
  nsstring *indexstr = [nsstring stringwithformat:@"%d",(int)indexpath.section];
  if ([dic[indexstr][indexpath.row][@"cell"] isequaltostring:@"maincell"]) {
    static nsstring *identifier = @"maincell";
    maincell *cell = [tableview dequeuereusablecellwithidentifier:identifier];
    
    if (cell == nil) {
      cell = [[maincell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier];
      cell.selectionstyle = uitableviewcellselectionstylegray;
    }
    
    if ([selectedarr containsobject:indexstr]) {
      cell.headerphoto.image = [uiimage imagenamed:[nsstring stringwithformat:@"%d.png",arc4random()%11]];
      cell.namelabel.text = dic[indexstr][indexpath.row][@"name"];
      cell.introductionlabel.text = @"滴滴雨点仿佛似流泪,滴在我冰冷的身躯";
      cell.networklabel.text = @"2g";
    }
    // ???
    if (indexpath.row == dataarray.count - 1) {
      cell.imageline.image = nil;
    }else{
      cell.imageline.image = [uiimage imagenamed:@"line"];
    }
    return cell;
  }else if ([dic[indexstr][indexpath.row][@"cell"] isequaltostring:@"attachedcell"]){
    static nsstring *detialidentifier = @"attachedcell";
    detialtableviewcell *cell = [tableview dequeuereusablecellwithidentifier:detialidentifier];
    
    if (cell == nil) {
      cell = [[detialtableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:detialidentifier];
      cell.selectionstyle = uitableviewcellseparatorstylenone;
      cell.imageline.image = [uiimage imagenamed:@"line"];
    }
    return cell;
  }
  return nil;
}

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath
{
  // todo:search
  [_tableview deselectrowatindexpath:indexpath animated:yes];
  nsstring *indexstr = [nsstring stringwithformat:@"%d",(int)indexpath.section];
  nsindexpath *path = nil;
  
  if ([dic[indexstr][indexpath.row][@"cell"] isequaltostring:@"maincell"]) {
    // todo:search
    path = [nsindexpath indexpathforitem:(indexpath.row + 1) insection:indexpath.section];
  }else{
    path = indexpath;
  }  
  if ([dic[indexstr][indexpath.row][@"state"] boolvalue]) {
    // 关闭附加cell
    nsmutabledictionary *dd = dic[indexstr][indexpath.row];
    nsstring *name = dd[@"name"];
    
    nsmutabledictionary *nameandstatedic = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",name,@"name",@"no",@"state", nil];
    
    switch (indexpath.section) {
      case 0:
      {
        grouparr0[(path.row-1)] = nameandstatedic;
        [grouparr0 removeobjectatindex:path.row];
      }
        break;
      case 1:
      {
        grouparr1[(path.row-1)] = nameandstatedic;
        [grouparr1 removeobjectatindex:path.row];
      }
        break;
      case 2:
      {
        grouparr2[(path.row-1)] = nameandstatedic;
        [grouparr2 removeobjectatindex:path.row];
      }
        break;
      case 3:
      {
        grouparr3[(path.row-1)] = nameandstatedic;
        [grouparr3 removeobjectatindex:path.row];
      }
        break;
      case 4:
      {
        grouparr4[(path.row-1)] = nameandstatedic;
        [grouparr4 removeobjectatindex:path.row];
      }
        break;
      case 5:
      {
        grouparr5[(path.row-1)] = nameandstatedic;
        [grouparr5 removeobjectatindex:path.row];
      }
        break;
      default:
        break;
    }
    
    [_tableview beginupdates];
    [_tableview deleterowsatindexpaths:@[path] withrowanimation:uitableviewrowanimationmiddle];
    [_tableview endupdates];
  }else{
    // 打开附加cell
    nsmutabledictionary *dd = dic[indexstr][indexpath.row];
    nsstring *name = dd[@"name"];
    
    nsmutabledictionary *nameandstatedic = [nsmutabledictionary dictionarywithobjectsandkeys:@"maincell",@"cell",name,@"name",@"yes",@"state", nil];
    switch (indexpath.section) {
      case 0:
      {
        grouparr0[(path.row-1)] = nameandstatedic;
        nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"attachedcell",@"cell",@"yes",@"state", nil];
        [grouparr0 insertobject:nameandstatedic1 atindex:path.row];
      }
        break;
      case 1:
      {
        grouparr1[(path.row-1)] = nameandstatedic;
        nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"attachedcell",@"cell",@"yes",@"state", nil];
        [grouparr1 insertobject:nameandstatedic1 atindex:path.row];
      }
        break;
      case 2:
      {
        grouparr2[(path.row-1)] = nameandstatedic;
        nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"attachedcell",@"cell",@"yes",@"state", nil];
        [grouparr2 insertobject:nameandstatedic1 atindex:path.row];
      }
        break;
      case 3:
      {
        grouparr3[(path.row-1)] = nameandstatedic;
        nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"attachedcell",@"cell",@"yes",@"state", nil];
        [grouparr3 insertobject:nameandstatedic1 atindex:path.row];
      }
        break;
      case 4:
      {
        grouparr4[(path.row-1)] = nameandstatedic;
        nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"attachedcell",@"cell",@"yes",@"state", nil];
        [grouparr4 insertobject:nameandstatedic1 atindex:path.row];
      }
        break;
      case 5:
      {
        grouparr5[(path.row-1)] = nameandstatedic;
        nsmutabledictionary *nameandstatedic1 = [nsmutabledictionary dictionarywithobjectsandkeys:@"attachedcell",@"cell",@"yes",@"state", nil];
        [grouparr5 insertobject:nameandstatedic1 atindex:path.row];
      }
        break;
      default:
        break;
    }
    [_tableview beginupdates];
    [_tableview insertrowsatindexpaths:@[path] withrowanimation:uitableviewrowanimationmiddle];
    [_tableview endupdates];
  }
}

-(void)buttonaction:(uibutton *)sender
{
  nsstring *string = [nsstring stringwithformat:@"%d",(int)(sender.tag-100)];
  
  //数组selectedarr里面存的数据和表头想对应,方便以后做比较
  if ([selectedarr containsobject:string])
  {
    [selectedarr removeobject:string];
  }
  else
  {
    [selectedarr addobject:string];
  }
  
  [_tableview reloaddata];
}

- (void)didreceivememorywarning {
  [super didreceivememorywarning];
  // dispose of any resources that can be recreated.
}



@end
#import <uikit/uikit.h>

@interface maincell : uitableviewcell

@property (strong, nonatomic) uilabel *namelabel;

@property (strong, nonatomic) uilabel *introductionlabel;

@property (strong, nonatomic) uilabel *networklabel;

@property (strong, nonatomic) uiimageview *headerphoto;

@property (strong, nonatomic) uiimageview *imageline;

@end
#import "maincell.h"

@implementation maincell

- (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier
{
  self = [super initwithstyle:style reuseidentifier:reuseidentifier];
  if (self) {
    // 头像
    _headerphoto = [[uiimageview alloc] initwithframe:cgrectmake(6*scalex, 5*scaley, 50*scalex, 50*scalex)];
    [self.contentview addsubview:_headerphoto];
    // 名字
    _namelabel = [[uilabel alloc] initwithframe:cgrectmake(60*scalex, 5*scaley, 200*scalex, 25*scalex)];
    _namelabel.font = [uifont systemfontofsize:15];
    [self.contentview addsubview:_namelabel];
    // 简介
    _introductionlabel = [[uilabel alloc] initwithframe:cgrectmake(60*scalex, 28*scaley, 240*scalex, 25*scalex)];
    _introductionlabel.backgroundcolor = [uicolor clearcolor];
    _introductionlabel.textcolor = [uicolor lightgraycolor];
    _introductionlabel.font = [uifont systemfontofsize:13];
    [self.contentview addsubview:_introductionlabel];
    
    // 网络
    _networklabel = [[uilabel alloc] initwithframe:cgrectmake(290*scalex, 5*scaley, 50*scalex, 25*scaley)];
    _networklabel.backgroundcolor = [uicolor clearcolor];
    _networklabel.textcolor = [uicolor lightgraycolor];
    _networklabel.font = [uifont systemfontofsize:13];
    [self.contentview addsubview:_networklabel];
    
    // 分割线
    _imageline = [[uiimageview alloc] initwithframe:cgrectmake(60*scalex, 60*scaley - 1, (320 - 60)*scalex, 1)];
    [self.contentview addsubview:_imageline];
  }
  return self;
}

@end
#import <uikit/uikit.h>

@interface detialtableviewcell : uitableviewcell

@property (strong, nonatomic) uiimageview *imageline;

@end
#import "detialtableviewcell.h"
#import "uibutton+initializer.h"
@implementation detialtableviewcell

- (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier
{
  self = [super initwithstyle:style reuseidentifier:reuseidentifier];
  if (self) {
    // 分割线
    _imageline = [[uiimageview alloc] initwithframe:cgrectmake(60*scalex, 40*scaley - 1, (320 - 60)*scaley, 1)];
    [self.contentview addsubview:_imageline];
    
    uibutton *btn1 = [uibutton initbuttonwithframe:cgrectmake(70*scalex, 9*scaley, 50*scalex, 20*scaley) title:@"语音" target:self selector:@selector(btnaction:)];
    btn1.tag = 100;
    
    uibutton *btn2 = [uibutton initbuttonwithframe:cgrectmake(130*scalex, 9*scaley, 50*scalex, 20*scaley) title:@"视频" target:self selector:@selector(btnaction:)];
    btn2.tag = 200;
    
    uibutton *btn3 = [uibutton initbuttonwithframe:cgrectmake(190*scalex, 9*scaley, 50*scalex, 20*scaley) title:@"图片" target:self selector:@selector(btnaction:)];
    btn3.tag = 300;
    
    uibutton *btn4 = [uibutton initbuttonwithframe:cgrectmake(250*scalex, 9*scaley, 50*scalex, 20*scaley) title:@"表情" target:self selector:@selector(btnaction:)];
    btn4.tag = 400;
    
    [self.contentview addsubview:btn1];
    [self.contentview addsubview:btn2];
    [self.contentview addsubview:btn3];
    [self.contentview addsubview:btn4];
  }
  return self;
}

- (void)btnaction:(uibutton *)sender
{
  switch (sender.tag) {
    case 100:
    {
      nslog(@"~~~~语音~~~~");
    }
      break;
    case 200:
    {
      nslog(@"~~~~视频~~~~");
    }
      break;
    case 300:
    {
      nslog(@"~~~~图片~~~~");
    }
      break;
    case 400:
    {
      nslog(@"~~~~表情~~~~");
    }
      break;
    default:
      break;
  }
}

- (void)awakefromnib {
  // initialization code
}

- (void)setselected:(bool)selected animated:(bool)animated {
  [super setselected:selected animated:animated];

  // configure the view for the selected state
}

@end
#import <uikit/uikit.h>

@interface uibutton (initializer)
/**
 * 初始化button
 *
 * @param frame    button的尺寸
 * @param target    button的目标对象
 * @param selector   点击button所触发的方法
 * @param image    button的背景图片
 * @param imagepressed button高亮时的图片
 *
 * @return button
 */
+ (uibutton *)initbuttonwithframe:(cgrect)frame target:(id)target selector:(sel)selector image:(nsstring *)image imagepressed:(nsstring *)imagepressed;
/**
 * 初始化button
 *
 * @param frame  button的尺寸
 * @param title  button的标题
 * @param target  button的目标对象
 * @param selector 点击button所触发的方法
 *
 * @return button
 */
+ (uibutton *)initbuttonwithframe:(cgrect)frame title:(nsstring *)title target:(id)target selector:(sel)selector;

@end
#import "uibutton+initializer.h"

@implementation uibutton (initializer)

+ (uibutton *)initbuttonwithframe:(cgrect)frame target:(id)target selector:(sel)selector image:(nsstring *)image imagepressed:(nsstring *)imagepressed
{
  uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];
  [button setframe:frame];
  uiimage *newimage = [uiimage imagenamed:image];
  [button setbackgroundimage:newimage forstate:0];
  uiimage *newpressedimage = [uiimage imagenamed:imagepressed];
  [button setbackgroundimage:newpressedimage forstate:uicontrolstatehighlighted];
  [button addtarget:target action:selector forcontrolevents:uicontroleventtouchupinside];
  return button;
}

+ (uibutton *)initbuttonwithframe:(cgrect)frame title:(nsstring *)title target:(id)target selector:(sel)selector
{
  uibutton *button = [uibutton buttonwithtype:uibuttontyperoundedrect];
  [button setframe:frame];
  [button settitle:title forstate:0];
  [button addtarget:target action:selector forcontrolevents:uicontroleventtouchupinside];
  return button;
}

@end

pch文件的代码:

#ifndef qqlist_prefixheader_pch
#define qqlist_prefixheader_pch

#define scalex [uiscreen mainscreen].bounds.size.width/320.0
#define scaley [uiscreen mainscreen].bounds.size.height/568.0

#endif

总结

以上就是在ios展开三级列表效果示例的全部内容,希望本文的内容对大家ios时能有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网