Select a table to display the results. Select a table to display the results.

Source: Internet
Author: User

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.