This example for you to share the iOS bookshelf effect of the specific implementation code for your reference, the specific contents are as follows
One, the effect chart
Second, engineering drawing
Third, the Code
RootViewController.h
#import <UIKit/UIKit.h>
@interface rootviewcontroller:uiviewcontroller
<uitableviewdatasource, Uitableviewdelegate>
{
nsmutablearray * dataarray;
UITableView * mytableview;
}
@end
Rootviewcontroller.m
#import "RootViewController.h"//cell #import "RootTableViewCell.h" @interface Rootviewcontroller () @end @implementat Ion Rootviewcontroller-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil {self = [super
Initwithnibname:nibnameornil Bundle:nibbundleornil];
if (self) {//Custom initialization} return self;
}-(void) viewdidload {[Super viewdidload];
Do no additional setup after loading the view.
Initialize background image [self initbackgroundview];
#pragma-mark-functions-(void) Initbackgroundview {self.title=@ "Bookshelf page";
Dataarray=[[nsmutablearray alloc]initwithobjects:@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", nil];
Mytableview = [[UITableView alloc]initwithframe:cgrectmake (0, 0, 416) Style:uitableviewstyleplain];
Mytableview.delegate = self;
Mytableview.datasource = self;
[Self.view Addsubview:mytableview]; } #pragma-mark-uitableviewdelegate-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (NSInteger ) SEction {return 3;}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) IndexPath {Retu
RN 376/3;
}-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath {
Roottableviewcell * cell = [TableView dequeuereusablecellwithidentifier:@ "ID"];
if (cell = = nil) {cell =[[roottableviewcell alloc]initwithstyle:uitableviewcellstylevalue1 reuseidentifier:@ "ID"];
} Cell.tag = Indexpath.row;
[Cell.bookleft addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside];
[Cell.bookmiddle addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside];
[Cell.bookright addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside]; [Cell.bookleft setbackgroundimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [DataArray
OBJECTATINDEX:INDEXPATH.ROW*3]]] forstate:uicontrolstatenormal]; [Cell.bookmiddle SetbackgroUndimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [DataArray Objectatindex:indexpath.row*3+1]]
Forstate:uicontrolstatenormal]; [Cell.bookright setbackgroundimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [DataArray
OBJECTATINDEX:INDEXPATH.ROW*3+2]]] forstate:uicontrolstatenormal];
NSLog (@ "--celll.tag--%ld", Cell.tag);
return cell; #pragma-mark-doclickactions-(void) ButtonClick: (uibutton*) btn {Roottableviewcell * cell = (Roottableviewcell *) [[BTN
Superview] Superview];
Nsindexpath * Path = [Mytableview Indexpathforcell:cell];
NSLog (@ "--click on the image, the coordinates-(%LD,%LD)-", Path.row,btn.tag);
}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated.
} @end
RootTableViewCell.h
#import <UIKit/UIKit.h>
@interface roottableviewcell:uitableviewcell
@property (Nonatomic,strong) UIButton * BOOKLEFT;
@property (Nonatomic,strong) UIButton * bookmiddle;
@property (Nonatomic,strong) UIButton * bookright;
@end
roottableviewcell.m
#import "RootTableViewCell.h" @implementation Roottableviewcell @synthesize bookleft;
@synthesize Bookmiddle;
@synthesize Bookright; -(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier {self = [super
Initwithstyle:style Reuseidentifier:reuseidentifier]; if (self) {//initialization code Uiimageview * imageview= [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, 320, 41
6/3)];
Imageview.image = [UIImage imagenamed:@ "Bookshelfcell.png"];
[Self addsubview:imageview];
Bookleft = [UIButton buttonwithtype:uibuttontypecustom];
Bookleft.frame = CGRectMake (10, 10, 280/3, 376/3-20);
Bookleft.tag = 1;
Bookmiddle = [UIButton buttonwithtype:uibuttontypecustom];
Bookmiddle.frame = CGRectMake (20+280/3, 10, 280/3, 376/3-20);
Bookmiddle.tag = 2;
Bookright = [UIButton buttonwithtype:uibuttontypecustom];
Bookright.frame = CGRectMake (30+280/3*2, 10, 280/3, 376/3-20);
Bookright.tag = 3;
[Self addsubview:bookleft]; [Self addsubview:bookmIddle];
[Self addsubview:bookright];
return self;
}
You can also combine the "iOS imitation ebook home to achieve Bookshelf layout style" This article to learn.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.