一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - IOS - IOS代碼筆記之仿電子書書架效果

IOS代碼筆記之仿電子書書架效果

2021-01-21 15:37iOS開發網 IOS

這篇文章主要為大家詳細介紹了IOS仿電子書書架效果的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了ios書架效果的具體實現代碼,供大家參考,具體內容如下

一、效果圖

 IOS代碼筆記之仿電子書書架效果

二、工程圖 

IOS代碼筆記之仿電子書書架效果

三、代碼
rootviewcontroller.h

?
1
2
3
4
5
6
7
8
9
10
#import <uikit/uikit.h>
 
@interface rootviewcontroller : uiviewcontroller
<uitableviewdatasource,uitableviewdelegate>
{
 nsmutablearray * dataarray;
 uitableview * mytableview;
}
 
@end

rootviewcontroller.m

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "rootviewcontroller.h"
//cell
#import "roottableviewcell.h"
 
@interface rootviewcontroller ()
 
@end
 
@implementation 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 any additional setup after loading the view.
 
 //初始化背景圖
 [self initbackgroundview];
 
}
#pragma -mark -functions
-(void)initbackgroundview
{
 self.title=@"書架頁面";
 
 dataarray=[[nsmutablearray alloc]initwithobjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9", nil];
 
 mytableview = [[uitableview alloc]initwithframe:cgrectmake(0, 0, 320, 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
{
 return 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(@"--點擊圖片的時候,所在的坐標-(%ld,%ld)--",path.row,btn.tag);
}
- (void)didreceivememorywarning
{
 [super didreceivememorywarning];
 // dispose of any resources that can be recreated.
}
 
@end

roottableviewcell.h

?
1
2
3
4
5
6
7
#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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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, 416/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;
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
  • IOSiOS實現控制屏幕常亮不變暗的方法示例

    iOS實現控制屏幕常亮不變暗的方法示例

    最近在工作中遇到了要將iOS屏幕保持常亮的需求,所以下面這篇文章主要給大家介紹了關于利用iOS如何實現控制屏幕常亮不變暗的方法,文中給出了詳細的...

    隨風13332021-04-02
  • IOSiOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    這篇文章主要介紹了iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果的相關資料,需要的朋友可以參考下...

    jiangamh8882021-01-11
  • IOSiOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)

    iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和

    這篇文章主要介紹了iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)的相關資料,需要的朋友可以參考下...

    CodingFire13652021-02-26
  • IOSiOS中MD5加密算法的介紹和使用

    iOS中MD5加密算法的介紹和使用

    MD5加密是最常用的加密方法之一,是從一段字符串中通過相應特征生成一段32位的數字字母混合碼。對輸入信息生成唯一的128位散列值(32個字符)。這篇文...

    LYSNote5432021-02-04
  • IOSiOS開發之視圖切換

    iOS開發之視圖切換

    在iOS開發中視圖的切換是很頻繁的,獨立的視圖應用在實際開發過程中并不常見,除非你的應用足夠簡單。在iOS開發中常用的視圖切換有三種,今天我們將...

    執著丶執念5282021-01-16
  • IOSiOS中UILabel實現長按復制功能實例代碼

    iOS中UILabel實現長按復制功能實例代碼

    在iOS開發過程中,有時候會用到UILabel展示的內容,那么就設計到點擊UILabel復制它上面展示的內容的功能,也就是Label長按復制功能,下面這篇文章主要給大...

    devilx12792021-04-02
  • IOSiOS開發技巧之狀態欄字體顏色的設置方法

    iOS開發技巧之狀態欄字體顏色的設置方法

    有時候我們需要根據不同的背景修改狀態欄字體的顏色,下面這篇文章主要給大家介紹了關于iOS開發技巧之狀態欄字體顏色的設置方法,文中通過示例代碼...

    夢想家-mxj8922021-05-10
  • IOS詳解iOS中多個網絡請求的同步問題總結

    詳解iOS中多個網絡請求的同步問題總結

    這篇文章主要介紹了詳解iOS中多個網絡請求的同步問題總結,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧...

    liang199111302021-03-15
主站蜘蛛池模板: 清纯唯美 亚洲 | 天天亚洲综合 | 日本中文字幕在线视频 | 国产精品拍拍拍福利在线观看 | 美女校花被调教出奶水 | 欧美操大逼视频 | chinese野外gay军人 | 国产精品久久香蕉免费播放 | 免费高清视频日本 | 国产国语videosex另类 | 思思91精品国产综合在线 | 国产精品51麻豆cm传媒 | 欧洲vodafonewifi日本 | 亚洲免费国产 | 男人j放进女人的p免费看视频 | 亚洲天堂免费看 | 婷婷去我也去 | 成人影院在线观看免费 | 97蜜桃网 | 欧美一二区视频 | 亚洲青草视频 | 99视频久久| 国产大秀视频一区二区三区 | 日韩欧美国产综合精品 | 糖心视频在线观看 | 国产a高清| 欧美精品亚洲精品日韩专区va | 福利视频一区二区牛牛 | 天天色天天舔 | 欧美男女爱爱视频 | 黑人巨大初黑人解禁作品 | 日本高清免费中文字幕不卡 | 五月天婷婷网亚洲综合在线 | 久久久久琪琪精品色 | 日本黄色网页 | 2021海角社区最新版 | s8sp加密路线和免费路线首页 | 日韩精品特黄毛片免费看 | 四虎影视4hutv最新地址在线 | 熟睡迷j系列小说 | 耽美肉文高h|