Source code Address: Https://github.com/EizoiOS/ImagePickerClass
As follows:
Add a picture to the cell, where the instance is the background shadow also as a picture, usually through a view to set its transparency, and the cell to assign it to the corresponding click event;
1: This is a cell view that handles the selected effect
EiaoAsset.h file
@interface eizoasset:uiview{ // Create a ImageView--used to add to the selected picture BOOL selected; // creates a bool value--Used to identify if there is no selected // through Alasset to obtain the corresponding resources @property (assign, nonatomic) ID parent; -(ID) Initwithasset: (alasset*) asset; -(BOOL) selected; -(void) toggleselection; @end
eiaoasset.m file: #import"EizoAsset.h"@interface Eizoasset () {Uiimageview* Assetimageview;//Show the ImageView of each picture} @end @implementation Eizoasset-(ID) Initwithasset: (Alasset *) Asset {if(self = [Super Initwithframe:cgrectmake (0,0,0,0)]) {Self.asset=Asset; Assetimageview=[[Uiimageview alloc]init]; Assetimageview.contentmode=Uiviewcontentmodescaleaspectfill; Assetimageview.image=[UIImage imagewithcgimage:[self.asset thumbnail]; //Alasset's thumbnail is a thumbnail image of the picture.[self addsubview:assetimageview]; Selectedview=[[Uiimageview alloc]init]; Selectedview.image= [UIImage imagenamed:@"Select.png"]; Selectedview.hidden=YES; [Self addsubview:selectedview]; } returnSelf ;}-(BOOL) selected {return!Selectedview.hidden;}-(void) setselected: (BOOL) _selected {[Selectedview Sethidden:!_selected];}//Add a gesture click on the cell that is the previous level the selected state also changes the bool value- (void) toggleselection {Selectedview.hidden= !Selectedview.hidden;}-(void) Setframe: (CGRect) frame {[Super Setframe:frame]; Assetimageview.frame=Self.bounds; Selectedview.frame=Self.bounds;} @end
Note: This side has the selected effect to add, just let it hide it first, but also set it to click the event triggered;Alasset is the data model, used to save some pictures of the data;
2: cell File:
EiaoAssetCell.h file
#import <UIKit/UIKit.h>#defineTopMargin 5@interface Eizoassetcell:uitableviewcell//How to create a cell-(Instancetype) Initwithassets: (Nsarray *) Assets Reuseidentifier: (NSString *) identifier;//the way to pass this assets-(void) Setassets: (Nsarray *) assets;//@property (nonatomic,retain) nsarray * linesassets;//an array of incoming pictures--should be all the pictures@endeiaoAssetCell. m File: #import"EizoAssetCell.h"#import"EizoAsset.h"@implementation Eizoassetcell-(Instancetype) Initwithassets: (Nsarray *) Assets Reuseidentifier: (NSString *) Identifier {if(self =[Super Initwithstyle:uitableviewcellstyledefault Reuseidentifier:identifier]) {Self.linesassets=assets; } returnSelf ;}-(void) layoutsubviews {cgfloat h= Self.bounds.size.height-TopMargin; CGFloat margin= (Self.bounds.size.width-4* h)/5.0; CGRect Frame=CGRectMake (Margin,topmargin, H, h); for(Eizoasset * Eizoassetinchself.linesassets) {eizoasset.frame=frame; UITapGestureRecognizer*tap =[[UITapGestureRecognizer alloc]initwithtarget:eizoasset Action: @selector (toggleselection)]; [Eizoasset Addgesturerecognizer:tap]; [Self addsubview:eizoasset]; Frame.origin.x= frame.origin.x + Frame.size.width +margin; }} @end
Note: The most important here is the code inside the Layoutsubviews, UITapGestureRecognizer the target to the Eizoasset view created above, so that the selected and reversed events created above can be invoked;
Table Selection Effect Show