Nonsense not much said, went straight to the subject.
The desired effect
1. Set window's root view controller as a Uitableviewcontroller
#import "AppDelegate.h"
#import "YCTableViewController.h"
@interface appdelegate ()
@end
@ Implementation Appdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];
Self.window.backgroundColor = [Uicolor whitecolor];
Self.window.rootViewController = [[Uinavigationcontroller alloc] initwithrootviewcontroller:[[ Yctableviewcontroller alloc] init];
[Self.window makekeyandvisible];
Return YES
}
2.UITableViewController
COPYRIGHT©2016 year Chason.
All rights reserved. #import <UIKit/UIKit.h> #import "DepositFeeHeader.h" #import "DepositFeeWithApplyTableViewCell.h" #import AppModel.h "#import" MyCollectionViewCell.h "#import" SectionHeaderViewCollectionReusableView.h "@interface Yctableviewcontroller:uitableviewcontroller<uicollectionviewdatasource, Uicollectionviewdelegate, Uicollectionviewdelegateflowlayout, Uiimagepickercontrollerdelegate, Uiactionsheetdelegate,
Uinavigationcontrollerdelegate> @property (nonatomic, strong) Nsmutablearray *dataarray; @property (nonatomic, strong) Nsmutablearray *ownhobby;//upload image array 1 @property (nonatomic, strong) Nsmutablearray *
imagearray;//upload Image Array 2 @property (nonatomic, strong) Uicollectionview *collection;
@property (nonatomic, strong) Uiactionsheet *actionsheet;
@property (nonatomic, strong) Appmodel *model;
@property (nonatomic, assign) Nsinteger reupdate;
@property (nonatomic, strong) NSString *imagestring; @property (nonatomic, assign) NsintegeR number; @end//copyright©2016 year Chason.
All rights reserved. #import "YCTableViewController.h"//Phone screen width and height #define Kscreenwidth [uiscreen mainscreen].bounds.size.width #define kscreenheight [UIScreen mainscreen].bounds.size.height @interface Yctableviewcontroller () @end @implementation Yctableviewcontroller-(void) viewdidload {[Super viewdidload]; _dataarray = [[Nsmutablearray alloc] Initwithcapacity:1
];
for (int i = 0; i < 3; i++) {Appmodel *model = [[Appmodel alloc] init];
[_dataarray Addobject:model];
} _ownhobby = [Nsmutablearray array];
_reupdate = 10000;//Assign initial value}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (NSInteger) Section {
Appmodel *model = _dataarray[section]; if ([model Is_open]) {return 1;}
else {return 0;}} -(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {[_ownhobby removeallobjects]; for (int i = 0; I < _ Dataarray.count;
i++) {_imagearray= [nsmutablearray array];
[_ownhobby Addobject:_imagearray]; } return _Dataarray.count; }-(CGFloat) TableView: (UITableView *) TableView heightforfooterinsection: (nsinteger) Section {Appmodel *model = _
Dataarray[section]; if (model. Is_open = = YES | | Section = = _dataarray.count-1) {return 0.01;}
else {return 10;}} -(UIView *) TableView: (UITableView *) TableView viewforfooterinsection: (nsinteger) Section {uiview *backview = [UIView
ALLOC] init];
Backview.backgroundcolor = [Uicolor Whitecolor];
return backview; }-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) section {return;}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {return}-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) Section {Depositfeeheader *depositHeader = [
TableView dequeuereusableheaderfooterviewwithidentifier:@ "deposit"]; if (Depositheader = = nil) {depositheader = [[Depositfeeheader alloc] initwithreuseidentifier:@ ' deposit ']; depositheade R.tag = 1000 + SectIon
[Depositheader.tap addtarget:self Action: @selector (ShowDetail:)];
CGFloat Rota;
Appmodel *model = _dataarray[section];
if ([model is_open] = = NO) {rota=0} else{rota=m_pi_2;} [UIView animatewithduration:0.1 animations:^{depositHeader.listImage.transform = cgaffinetransformmakerotation (
Rota);
}];
return depositheader; }-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath {if (
Indexpath.section!= _reupdate) {Appmodel *model = _dataarray[indexpath.section]; Depositfeewithapplytableviewcell *cell = [[Depositfeewithapplytableviewcell alloc] Initwithstyle:
Uitableviewcellstyledefault reuseidentifier:@ "Applycell"];
Uicollectionviewflowlayout *flowlayout = [[Uicollectionviewflowlayout alloc]init];
flowlayout.minimuminteritemspacing = 5;
flowlayout.minimumlinespacing = 5;
Flowlayout.sectioninset = Uiedgeinsetsmake (0, 5, 0, 10);
Flowlayout.itemsize = Cgsizemake (40, 40); _collection = [[Uicollectionview alloc]initwithframe:cgrectMake (Ten, cell.backview.frame.size.width-20,) collectionviewlayout:flowlayout]; [_collection Registerclass:[sectionheaderviewcollectionreusableview class] Forsupplementaryviewofkind:
Uicollectionelementkindsectionheader withreuseidentifier:@ "Head"];
_collection.tag = indexpath.section;
_collection.bounces = NO;
_collection.delegate = self;
_collection.datasource = self;
_collection.backgroundcolor = [Uicolor Whitecolor];
[_collection Registerclass:[mycollectionviewcell class] forcellwithreuseidentifier:@ "identifier"];
[Cell.backview addsubview:_collection];
[Cell.shouldbtn addtarget:self Action: @selector (upimage:) forcontrolevents:uicontroleventtouchupinside];
Cell.shouldBtn.tag = Indexpath.row + 2000;
Cell.selectionstyle = Uitableviewcellselectionstylenone;
return cell;
}else {return Nil}} Processing of photos-(void) Upimage: (UIButton *) btn {}-(void) Textfiledshow {if ([_ownhobby[_number] count] = 9) {Uialertcontrol Ler *alert1 = [Uialertcontroller alertcontrollerwithtitle:@ "Upload photos notCan be more than 9, click the picture can delete "message:@" "Preferredstyle:uialertcontrollerstylealert]; Uialertaction *action = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault handler:^ (UIAlertAction
* _nonnull action) {}];
[Alert1 addaction:action];
[Self.navigationcontroller presentviewcontroller:alert1 Animated:yes Completion:nil];
else {[self callactionsheet];}} Balloon tip Photo Source-(void) Callactionsheet {if ([Uiimagepickercontroller issourcetypeavailable: Uiimagepickercontrollersourcetypecamera]) {self.actionsheet = [[Uiactionsheet alloc] initwithtitle:@ "Select Photos" delegate:
Self cancelbuttontitle:@ "Cancel" Destructivebuttontitle:nil otherbuttontitles:@ "take photos", @ "select from album", Nil]; }else {self.actionsheet = [[Uiactionsheet alloc] initwithtitle:@ "Select Photos" delegate:self "Cancel"
Destructivebuttontitle:nil otherbuttontitles:@ "from album selection", Nil];
} [Self.actionsheet ShowInView:self.tableView]; }-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) buttonindex {NSUInteger SourcEType = uiimagepickercontrollersourcetypephotolibrary; Pand whether to support camera if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {switch ( Buttonindex) {Case 0:sourcetype = Uiimagepickercontrollersourcetypecamera, Case 1:sourcetype = Uiimagepickercont
Rollersourcetypephotolibrary;
Break
Default:return; }}else {if (Buttonindex = = 1) {return;}
else {sourcetype = Uiimagepickercontrollersourcetypesavedphotosalbum;}}
Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init];
Imagepicker.delegate = self;
imagepicker.allowsediting = YES;
Imagepicker.sourcetype = sourcetype;
[Self.navigationcontroller presentviewcontroller:imagepicker Animated:yes completion:^{}]; }-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (nsdictionary<
NSString *,id> *) Info {[Picker dismissviewcontrolleranimated:yes completion:^{}]; [_ownhobby[_number] Addobject:[info Objectforkey:uiimagepickercontRolleroriginalimage]];
[_collection Reloaddata];
}
-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) Indexpath {_number = Collectionview.tag; if ([_ownhobby[_number] count] = = Indexpath.row) {Mycollectionviewcell *cell =
[CollectionView dequeuereusablecellwithreuseidentifier:@ "identifier" forindexpath:indexpath];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Textfiledshow)];
[Cell.imageview Addgesturerecognizer:tap];
cell.imageView.userInteractionEnabled = YES;
Cell.cellstyle = Cellstyleadd;
Cell.layer.masksToBounds = NO;
cell.layer.borderWidth = 0;
Cell.layer.cornerRadius = 0;
[Cell layoutsubviews];
return cell; else {Mycollectionviewcell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:@ "identifier"
Forindexpath:indexpath];
Cell.photo.image = _ownhobby[_number][indexpath.row];
Cell.cellstyle = 1;
[Cell layoutsubviews];
[Cell.imageview Removefromsuperview];
return cell; }-(Nsinteger) numberofsectionsIncollectionview: (Uicollectionview *) CollectionView {return 1;}-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) Section {return [_ownhobby[_number] count] + 1;} #pragma mark header view Size- (cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout *) collectionviewlayout Referencesizeforheaderinsection: (Nsinteger) Section {cgsize size = {0.01, 0.01}; return size;} #pragma mark per item size-(CG Size) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout *) collectionviewlayout Sizeforitematindexpath: (Nsindexpath *) Indexpath {return cgsizemake (+);}-(CGFloat) lengthwithstring: (NSString *) string {return [string length];}-(void) CollectionView: (Uicollectionview *) CollectionView Didselectitematindexpath: (
Nsindexpath *) Indexpath {if ([_ownhobby[_number] count]) {[_ownhobby[_number] removeObjectAtIndex:indexPath.row];
[_collection Reloaddata]; }}-(void) ShowDetail: (UitapgesturerecognizER *) Tap {Appmodel *model = _dataarray[tap.view.tag-1000]; if ([model Is_open]) {model.
Is_open = NO; }else {model.
Is_open = YES; } [Self.tableview Reloadsections:[nsindexset indexsetwithindex:tap.view.tag-1000] WithRowAnimation:
Uitableviewrowanimationnone]; } @end
3. Custom header and cell for TableView
Header//copyright©2016 year Chason.
All rights reserved. #import <UIKit/UIKit.h> @interface Depositfeeheader:uitableviewheaderfooterview @property (nonatomic, strong
) Uilabel *titlelabel;
@property (nonatomic, strong) Uiimageview *listimage;//tail button @property (nonatomic, strong) Uigesturerecognizer *tap; @end//copyright©2016 year Chason.
All rights reserved. #import "DepositFeeHeader.h"//Phone screen width and height #define Kscreenwidth [uiscreen mainscreen].bounds.size.width #define kscreenheight [UIScreen mainscreen].bounds.size.height @implementation Depositfeeheader-(instancetype) Initwithreuseidentifier: (NSString *) reuseidentifier {self = [super Initwithreuseidentifier:reuseidentifier]; if (self {UIView *backview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, Kscreenwidth,)]; backview.backgroundcolor = [UICo
Lor Whitecolor];
[Self addsubview:backview];
Self.titlelabel = [[Uilabel alloc] Initwithframe:cgrectmake (A, kScreenWidth-45, 20)];
Self.titleLabel.text = @ "Vehicle deposit"; Self.titleLabel.userInteractionEnabled = YES;
Self.titleLabel.textColor = [Uicolor Graycolor];
[Backview AddSubview:self.titleLabel];
Self.listimage = [[Uiimageview alloc] Initwithframe:cgrectmake (kScreenWidth-25, 10, 10, 20)];
Self.listImage.image = [UIImage imagenamed:@ "Jiantou.png"];
[Backview AddSubview:self.listImage];
Uiimageview *headerline = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, kscreenwidth, 1)];
Headerline.image = [UIImage imagenamed:@ "line"];
[Backview Addsubview:headerline];
Uiimageview *footerline = [[Uiimageview alloc] Initwithframe:cgrectmake (0,, Kscreenwidth, 1)];
Footerline.image = [UIImage imagenamed:@ "line"];
[Backview Addsubview:footerline];
Self.tap = [[UITapGestureRecognizer alloc] init];
[Self addGestureRecognizer:self.tap];
return self; } @end//cell//copyright©2016 year Chason.
All rights reserved. #import <UIKit/UIKit.h> @interface Depositfeewithapplytableviewcell:uitableviewcell @property (nonatomic,
Strong) UIView *backview; @prOperty (nonatomic, strong) UIButton *camerabtn;
@property (nonatomic, strong) Uiimageview *photoimg;
@property (nonatomic, strong) Uilabel *updatepresent;
@property (nonatomic, strong) UIButton *shouldbtn; @end//copyright©2016 year Chason.
All rights reserved. #import "DepositFeeWithApplyTableViewCell.h"//mobile screen width and height #define Kscreenwidth [UIScreen mainscreen]. Bounds.size.width #define Kscreenheight [UIScreen mainscreen].bounds.size.height @implementation Depositfeewithapplytableviewcell-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style ReuseIdentifier: ( NSString *) Reuseidentifier {self = [super Initwithstyle:style reuseidentifier:reuseidentifier]; if (self) {_backview = [
[UIView alloc] Initwithframe:cgrectmake (A, kScreenWidth-40, 170)];
[Self addsubview:_backview];
[Self adddottedlinefromimageview:_backview];
Self.updatepresent = [[Uilabel alloc] Initwithframe:cgrectmake (0, 0, kScreenWidth-40, 20)]; Self.updatePresent.center = Cgpointmake (kScreenWidth-40)/2, 110);
Self.updatePresent.text = @ "Click on the top left button to add photos";
Self.updatePresent.textColor = [Uicolor Lightgraycolor];
Self.updatePresent.textAlignment = Nstextalignmentcenter;
Self.updatePresent.font = [Uifont systemfontofsize:14];
[_backview addSubview:self.updatePresent];
SELF.SHOULDBTN = [UIButton buttonwithtype:uibuttontypecustom];
Self.shouldBtn.frame = CGRectMake (kScreenWidth-40)/2-45, 130, 90, 20);
[Self.shouldbtn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
[Self.shouldbtn settitle:@ "immediately upload" forstate:uicontrolstatenormal];
Self.shouldBtn.layer.cornerRadius = 5;
Self.shouldBtn.backgroundColor = [Uicolor colorwithred:18/255.0 green:129/255.0 blue:201/255.0 alpha:1];
[_backview AddSubview:self.shouldBtn];
return self;
///Add dashed box-(void) Adddottedlinefromimageview: (UIView *) superview{cgfloat w = superView.frame.size.width;
CGFloat h = superView.frame.size.height;
CGFloat padding = 20; Create four ImageView as border for (Nsinteger i = 0; i<4; i++) {Uiimageview *imageview = [UIImageView alloc] init];
Imageview.backgroundcolor = [Uicolor Clearcolor]; if (i = = 0) {imageview.frame = CGRectMake (0, 0, W, padding);} else if (i = = 1) {imageview.frame = CGRectMake (0, 0, padding, h);} else if (i = = 2) {imageview.frame = CGRectMake (0, H-padding, W, padding);}
else if (i = = 3) {imageview.frame = CGRectMake (w-padding, 0, padding, h);}
[Superview Addsubview:imageview]; Uigraphicsbeginimagecontext (imageView.frame.size);
Start drawing lines [Imageview.image drawinrect:cgrectmake (0, 0, ImageView.frame.size.width, imageView.frame.size.height)]; Cgcontextsetlinecap (Uigraphicsgetcurrentcontext (), kcglinecapround);
Set line End shape CGFloat lengths[] = {10,5};
Cgcontextref line = Uigraphicsgetcurrentcontext (); Cgcontextsetstrokecolorwithcolor (line, [Uicolor Blackcolor].
Cgcolor); Cgcontextsetlinedash (line, 0, lengths, 2); Draw dashed Cgcontextmovetopoint (line, 0, 0); Start drawing lines if (i = = 0) {Cgcontextaddlinetopoint (line, W, 0);} else if (i = = 1) {cgcontextaddlinetopoint (line, 0, W);}
else if (i = = 2) {Cgcontextmovetopoint (line, 0, padding);
Cgcontextaddlinetopoint (line, w, padding);
}else if (i = = 3) {Cgcontextmovetopoint (line, padding, 0);
Cgcontextaddlinetopoint (line, padding, W);
} cgcontextstrokepath (line);
Imageview.image = Uigraphicsgetimagefromcurrentimagecontext (); }} @end
4.collectionView layout and custom item
#import <UIKit/UIKit.h> @interface Sectionheaderviewcollectionreusableview:uicollectionreusableview @
Property (Nonatomic, Strong) Uilabel *titlelabel; @end #import "SectionHeaderViewCollectionReusableView.h" @implementation Sectionheaderviewcollectionreusableview-( Instancetype) initWithFrame: (CGRect) frame {self = [super Initwithframe:frame]; if (self) {[self createviews];} return SE
Lf
}-(void) createviews {_titlelabel = [[Uilabel alloc]init];
[Self Addsubview:_titlelabel]; }-(void) layoutsubviews {[Super layoutsubviews]; _titlelabel.frame = CGRectMake (M, 375,); _titlelabel.font = [UIF
Ont systemfontofsize:20]; @end CollectionView Item #import <UIKit/UIKit.h> @interface mycollectionviewcell:uicollectionviewcell typedef
Enum:nsinteger {cellstyledefault = 0, cellstyleselected = 1, Cellstyleadd = 2,}collectionviewcellstyle;
@property (nonatomic, assign) Collectionviewcellstyle CellStyle;
@property (nonatomic, strong) Uiimageview *photo; @property (Nonatomic, StRong) Uiimageview *imageview;
@property (nonatomic, strong) Nsarray *array;
@property (nonatomic, strong) Nsmutablearray *dataarray;
-(void) layoutsubviews; @end #import "MyCollectionViewCell.h" @implementation Mycollectionviewcell-(Instancetype) initWithFrame: (CGRect) frame {self = [super Initwithframe:frame]; if (self) {_photo = [[Uiimageview alloc]init]; _imageview = [[Uiimageview All
Oc]init];
return self;
}-(void) layoutsubviews {[Super layoutsubviews];
[_photo SetFrame:self.bounds];
_imageview.frame = Self.bounds; Switch (_cellstyle) {Case cellStyleDefault:self.layer.borderColor = [Uicolor colorwithred:0 green:0.68 blue:0.94 Alpha: 1].
Cgcolor;
Self.layer.masksToBounds = YES;
Self.layer.borderWidth = 1.8;
Self.layer.cornerRadius = 20;
Self.backgroundcolor = [Uicolor Whitecolor];
[Self.contentview Addsubview:_photo];
Break Case CellStyleSelected:self.layer.borderColor = [Uicolor colorwithred:0 green:0.68 blue:0.94 alpha:1].
Cgcolor;
Self.layer.masksToBounds = YES; Self.layer.bordeRwidth = 1.8;
Self.layer.cornerRadius = 20;
Self.backgroundcolor = [Uicolor colorwithred:0 green:0.68 blue:0.94 alpha:1];
[Self.contentview Addsubview:_photo];
Break
Case CELLSTYLEADD: [Self.imageview setimage:[uiimage imagenamed:@ "Addphoto.png"]];
Self.backgroundcolor = [Uicolor Whitecolor];
[Self.contentview Addsubview:_imageview];
Break
Default:break; }} @end
5.model
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface appmodel:nsobject
@ Property (Nonatomic, assign) BOOL Is_open;
@end
#import "AppModel.h"
@implementation appmodel
@end
//Set model is to set a variable of type bool, Used to record whether the TableView cell expands to perform reloadsection operations, animate or shrink.