How to implement an accordion view for an iPhone SDK app?

前端 未结 6 2094
一整个雨季
一整个雨季 2020-12-02 13:41

Has anyone seen an implementation of an \"accordion\" (maybe called \"animated outline\") view for the iPhone? I found an example project for Cocoa, but before trying a port

6条回答
  •  死守一世寂寞
    2020-12-02 14:21

    Every solution that I found was using UITableView, which didn't work for me, because I didn't display tabular data. This is why I created AccordionView control. Usage is pretty straightforward:

    AccordionView *accordion = [[AccordionView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
    [self addSubview:accordion];
    
    // Only height is taken into account, so other parameters are just dummy
    UIButton *header1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 30)];
    [header1.titleLabel setText:@"First row"];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 200)];
    // ... add subviews to view1
    
    [accordion addHeader:header1 withView:view1];
    
    // ... add more panels
    
    [accordion setSelectedIndex:0];
    

    In real life it looks like this:

    enter image description here

    Black bars are headers and you can customize them all you want (I'm using Three20).

提交回复
热议问题