Table Selection Effect Show

Source: Internet
Author: User

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

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.