In fact, very early wanted to write a blog, just feel that their technology can not, writing something technical is not strong, write out also no use, but later think, write blog record development encountered problems are also good ....
Today I want to write is TableView suspension effect, because our company recently in the development community, that is, and Baidu bar paste similar, nested in the application, and in which each of the posts to like this effect
The beginning is not to do this effect, directly write a tableview, and then asked the next to do the Android side, the original is the effect of the shadow ...
Speaking of Here, I believe many students know, well, we start on the code, the first is to create TableView, this will not have to say, this is the creation of TableView. m file
#import "ViewController.h"#import "DemoCell.h"//Screen Width#defineScreen_width ([[UIScreen mainscreen] bounds].size.width)//Screen Height#defineScreen_height ([[UIScreen mainscreen] bounds].size.height)@interfaceViewcontroller () <UITableViewDataSource,UITableViewDelegate>@property (nonatomic,strong) UITableView*TableView; @property (nonatomic,assign) cgfloat height;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; [Self Createtabelview];}- (void) createtabelview{Self.tableview= [[UITableView alloc] Initwithframe:cgrectmake (0, -, Screen_width, screen_height- -) Style:uitableviewstyleplain]; Self.tableview.Delegate=Self ; Self.tableView.dataSource=Self ; Self.tableView.separatorStyle=Uitableviewcellseparatorstylenone; [Self.view AddSubview:self.tableView];}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return 5;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//pay attention to reuse StaticNSString *cellid =@"Cell"; Democell*cell =[TableView Dequeuereusablecellwithidentifier:cellid]; if(Cell = =Nil) {Cell=[[Democell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]; } returncell;}- (void) didreceivememorywarning {[Super didreceivememorywarning];}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return[Democell GetHeight] +Ten;}@end
Then the custom cell, custom cell to note because to write the suspension effect, so I think is to add a layer of view to the cell, the view frame is smaller than the cell Contentview, in the setting of the shadow of the border, you can write the suspension effect, This is the. m file for the custom cell
#import "DemoCell.h"#defineScreen_width ([[UIScreen mainscreen] bounds].size.width)#defineScreen_height ([[UIScreen mainscreen] bounds].size.height)@interfaceDemocell () @property (nonatomic,strong) UIView*Bgview;@end@implementationDemocell-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier{if(self =[Super Initwithstyle:style Reuseidentifier:reuseidentifier]) {[Self createui]; } returnSelf ;}//Here's the point .- (void) createui{//Create a UIView a lap smaller than Self.contentviewSelf.bgview = [[UIView alloc] Initwithframe:cgrectmake (Ten,5, Screen_width- -, -)]; Self.bgView.backgroundColor=[Uicolor Whitecolor]; //to set a shadow on a bgview borderSelf.bgView.layer.shadowOffset = Cgsizemake (1,1); Self.bgView.layer.shadowOpacity=0.3; Self.bgView.layer.shadowColor=[Uicolor Blackcolor]. Cgcolor; [Self.contentview AddSubview:self.bgView];}+(cgfloat) getheight{//Here you can calculate the height, dynamic adjustment return -;}@end
Run up, isn't that awesome
End, the first blog is written here, even if no one to see (or want someone to see), I will also write down the oh ...
Tableviewcell hover effect in iOS development