Select a table to display the results. Select a table to display the results.
Source code: https://github.com/EizoiOS/ImagePickerClass
As follows:
Add an image to the cell. The example here uses the background shadow as an image. You can set its transparency through a VIEW; also, the cell is assigned to the corresponding click event;
1: This is the cell view, used to process the selected results
EiaoAsset. h file
@ Interface EizoAsset: UIView {UIImageView * selectedView; // create an ImageView -- used to add it to the selected image BOOL selected; // create a bool value -- used to identify whether selected} @ property (strong, nonatomic) ALAsset * asset; // obtain the corresponding resource @ property (assign, nonatomic) through ALAsset) id parent;-(id) initWithAsset :( ALAsset *) asset;-(BOOL) selected;-(void) toggleSelection; @ end
EiaoAsset. m file: # import "EizoAsset. h "@ interface EizoAsset () {UIImageView * assetImageView; // display the ImageView of each image} @ 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 imag EWithCGImage: [self. asset thumbnail]; // The thumbnail of ALAsset is the thumbnail of the image [self addSubview: assetImageView]; selectedView = [[UIImageView alloc] init]; selectedView. image = [UIImage imageNamed: @ "Select.png"]; selectedView. hidden = YES; [self addSubview: selectedView];} return self;}-(BOOL) selected {return! SelectedView. hidden;}-(void) setSelected :( BOOL) _ selected {[selectedView setHidden :! _ Selected];} // a gesture is added to the cell, that is, the previous layer. Click to change the selected status, that is, to change 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: You have added the selected effect to hide it first and set the event triggered by clicking it. ALAsset is the data model used to store some image data;
2: Cell file:
EiaoAssetCell. h file
# Import <UIKit/UIKit. h> # define topMargin 5 @ interface EizoAssetCell: UITableViewCell // cell creation method-(instancetype) initWithAssets :( NSArray *) assets reuseIdentifier :( NSString *) identifier; // Method for inputting this assets-(void) setAssets :( NSArray *) assets; // @ property (nonatomic, retain) NSArray * linesAssets; // Input Image array -- it should be all images @ endeiaoAssetCell. m file: # import "EizoAssetCell. h "# import" EizoAsset. h "@ implementation events-(instancetype) initWithAssets :( NSArray *) assets reuseIdentifier :( NSString *) identifier {if (self = [super initWithStyle: inclureuseidentifier: identifier]) {self. linesAssets = assets;} return self;}-(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 * eizoAsset in self. linesAssets) {eizoAsset. frame = frame; Parameters * tap = [[externalloc] initWithTarget: eizoAsset action: @ selector (toggleSelection)]; [eizoAsset parameters: tap]; [self addSubview: eizoAsset]; frame. origin. x = frame. origin. x + frame. size. width + margin; }}@ end
Note: the most important thing here is the code in layoutSubviews. UITapGestureRecognizer points the target to the EizoAsset view created above, so that you can call the selected and reversed events created above;