当前位置:首页 > 通信资讯 > 正文

效果图如下:

ios展开三级列表效果示例(ios展开三级列表效果示例)ios展开三级列表效果示例(ios展开三级列表效果示例)

?
1 2 3 4 5 6 7 8 #import <uikit/uikit.h> @interface appdelegate : uiresponder <uiapplicationdelegate> @property (strong, nonatomic) uiwindow *window; @end
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #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
?
1 2 3 4 5 #import <uikit/uikit.h> @interface rootviewcontroller : uiviewcontroller @end
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 #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
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #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
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #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
?
1 2 3 4 5 6 7 #import <uikit/uikit.h> @interface detialtableviewcell : uitableviewcell @property (strong, nonatomic) uiimageview *imageline; @end
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 #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
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #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
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #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文件的代码:

?
1 2 3 4 5 6 7 #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时能有所帮助。

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。