国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

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

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

服務器之家 - 編程語言 - IOS - IOS 自定義UICollectionView的頭視圖或者尾視圖UICollectionReusableView

IOS 自定義UICollectionView的頭視圖或者尾視圖UICollectionReusableView

2021-02-28 14:43Jack__Long IOS

這篇文章主要介紹了IOS 自定義UICollectionView的頭視圖或者尾視圖UICollectionReusableView的相關資料,需要的朋友可以參考下

ios 自定義uicollectionview的頭視圖或者尾視圖uicollectionreusableview

其實看標題就知道是需要繼承于uicollectionreusableview,實現一個滿足自己需求的視圖.那么如何操作了,看下面代碼:

?
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
viewcontroller.m文件中
 
#import "viewcontroller.h"
#import "lshcontrol.h"
#import "shcollectionreusableview.h"
#import "shcollectionviewcell.h"
 
#define shcollectionviewcellidetifiler  @"collectionviewcell"
#define shcollectionreusableviewheader  @"collectionheader"
#define shcollectionreusableviewfooter  @"collectionfooter"
 
@interface viewcontroller ()<uicollectionviewdelegate,uicollectionviewdatasource>{
  nsarray *recipeimages;
  nsarray *heardertitlearray;
}
 
 
@property(nonatomic,strong) uicollectionview *rightcollectionview;
 
@end
 
@implementation viewcontroller
 
- (void)viewdidload {
 
  [super viewdidload];
 
  nsarray *maindishimages = [nsarray arraywithobjects:@"egg_benedict.jpg", @"full_breakfast.jpg", @"ham_and_cheese_panini.jpg", @"ham_and_egg_sandwich.jpg", @"hamburger.jpg", @"instant_noodle_with_egg.jpg", @"japanese_noodle_with_pork.jpg", @"mushroom_risotto.jpg", @"noodle_with_bbq_pork.jpg", @"thai_shrimp_cake.jpg", @"vegetable_curry.jpg", nil];
  nsarray *drinkdessertimages = [nsarray arraywithobjects:@"angry_birds_cake.jpg", @"creme_brelee.jpg", @"green_tea.jpg", @"starbucks_coffee.jpg", @"white_chocolate_donut.jpg", nil];
  recipeimages = [nsarray arraywithobjects:maindishimages, drinkdessertimages, nil];
 
  heardertitlearray=@[@"分區1",@"分區2"];
 
  [self createcollectionview];
 
}
 
-(void)createcollectionview{
 
  uicollectionviewflowlayout *flowlayout=[[uicollectionviewflowlayout alloc] init];
  flowlayout.minimuminteritemspacing=0.f;//item左右間隔
  flowlayout.minimumlinespacing=5.f;//item上下間隔
  flowlayout.sectioninset=uiedgeinsetsmake(5,15,5, 15);//item對象上下左右的距離
  flowlayout.itemsize=cgsizemake(80, 80);//每一個 item 對象大小
  flowlayout.scrolldirection=uicollectionviewscrolldirectionvertical;//設置滾動方向,默認垂直方向.
  flowlayout.headerreferencesize=cgsizemake(self.view.frame.size.width, 30);//頭視圖的大小
  flowlayout.footerreferencesize=cgsizemake(self.view.frame.size.width, 30);//尾視圖大小
 
  self.rightcollectionview= [lshcontrol createcollectionviewfromframe:self.view.frame collectionviewlayout:flowlayout datasource:self delegate:self backgroudcolor:[uicolor whitecolor]];
 
  //自定義重用視圖
  [self.rightcollectionview registernib:[uinib nibwithnibname:@"shcollectionviewcell" bundle:nil] forcellwithreuseidentifier:shcollectionviewcellidetifiler];
 
  [self.rightcollectionview registerclass:[shcollectionreusableview class] forsupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:shcollectionreusableviewheader];
 
  //使用原有重用視圖
  [self.rightcollectionview registerclass:[uicollectionreusableview class] forsupplementaryviewofkind:uicollectionelementkindsectionfooter withreuseidentifier:shcollectionreusableviewfooter ];
 
  [self.view addsubview:self.rightcollectionview];
 
}
 
- (nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview
{
  return [recipeimages count];
}
 
- (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section{
  return [[recipeimages objectatindex:section] count];
}
 
- (uicollectionreusableview *)collectionview:(uicollectionview *)collectionview viewforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath
{
  uicollectionreusableview *reusableview = nil;
 
  if (kind == uicollectionelementkindsectionheader) {
 
    shcollectionreusableview *headerview = [collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:shcollectionreusableviewheader forindexpath:indexpath];
    /**
     *
     * 注意:雖然這里沒有看到明顯的initwithframe方法,但是在獲取重用視圖的時候,系統會自動調用initwithframe方法的.所以在initwithframe里面進行初始化操作,是沒有問題的!
     */
 
    [headerview getshcollectionreusableviewheardertitle:heardertitlearray[indexpath.section]];
 
    reusableview = headerview;
  }
 
  if (kind == uicollectionelementkindsectionfooter) {
 
    uicollectionreusableview *footerview = [collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionfooter withreuseidentifier:shcollectionreusableviewfooter forindexpath:indexpath];
    /**
     *  如果頭尾視圖沒什么很多內容,直接創建對應控件進行添加即可,無需自定義.
     */
    footerview.backgroundcolor=[uicolor redcolor];
    reusableview = footerview;
  }
 
  return reusableview;
}
 
 
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath{
 
  /**
   *
   *  這里自定義cell,使用xib進行布局.對于如何使用xib創建視圖,不明白的,可以看我之前寫的一篇文章.
   */
 
 
  shcollectionviewcell *cell = (shcollectionviewcell *)[collectionview dequeuereusablecellwithreuseidentifier:shcollectionviewcellidetifiler forindexpath:indexpath];
 
  uiimageview *recipeimageview = (uiimageview *)[cell viewwithtag:100];
  recipeimageview.image = [uiimage imagenamed:[recipeimages[indexpath.section] objectatindex:indexpath.row]];
  cell.backgroundview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"photo-frame-2.png"]];
 
  return cell;
}
 
@end

自定義uicollectionviewcell,使用 xib進行布局

?
1
2
3
4
5
6
7
8
9
10
11
12
13
#import <uikit/uikit.h>
 
@interface shcollectionviewcell : uicollectionviewcell
 
@property (weak, nonatomic) iboutlet uiimageview *recipeimageview;
 
@end
 
#import "shcollectionviewcell.h"
@implementation shcollectionviewcell
 
 
@end

自定義uicollectionreusableview,手寫代碼進行布局

?
1
2
3
4
5
6
7
8
9
10
11
#import <uikit/uikit.h>
 
@interface shcollectionreusableview : uicollectionreusableview
 
/**
 *  聲明相應的數據模型屬性,進行賦值操作,獲取頭視圖或尾視圖需要的數據.或者提供一個方法獲取需要的數據.
 */
 
-(void)getshcollectionreusableviewheardertitle:(nsstring *)title;
 
@end
?
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
#import "shcollectionreusableview.h"
#import "lshcontrol.h"
 
@interface shcollectionreusableview (){
 
  uilabel *titlelabel;
}
 
@end
 
@implementation shcollectionreusableview
 
 
-(id)initwithframe:(cgrect)frame{
 
  self=[super initwithframe:frame];
 
  if (self) {
 
    self.backgroundcolor=[uicolor greencolor];
    [self createbasicview];
  }
  return self;
 
}
 
/**
 *  進行基本布局操作,根據需求進行.
 */
-(void)createbasicview{
 
 
 titlelabel=[lshcontrol createlabelwithframe:cgrectmake(5, 0,self.frame.size.width-50, self.frame.size.height) font:[uifont systemfontofsize:14.0] text:@"" color:[uicolor graycolor]];
 [self addsubview:titlelabel];
 
 
}
 
 
/**
 *  設置相應的數據
 *
 *  @param title
 */
-(void)getshcollectionreusableviewheardertitle:(nsstring *)title{
 
  titlelabel.text=title;
 
}
 
@end

效果如下圖:

IOS 自定義UICollectionView的頭視圖或者尾視圖UICollectionReusableViewIOS 自定義UICollectionView的頭視圖或者尾視圖UICollectionReusableView

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

延伸 · 閱讀

精彩推薦
  • IOSiOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

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

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

    jiangamh8882021-01-11
  • IOS詳解iOS中多個網絡請求的同步問題總結

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

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

    liang199111312021-03-15
  • IOSiOS開發技巧之狀態欄字體顏色的設置方法

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

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

    夢想家-mxj8922021-05-10
  • IOSiOS實現控制屏幕常亮不變暗的方法示例

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

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

    隨風13332021-04-02
  • IOSiOS開發之視圖切換

    iOS開發之視圖切換

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

    執著丶執念5282021-01-16
  • IOSiOS中MD5加密算法的介紹和使用

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

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

    LYSNote5432021-02-04
  • IOSiOS中UILabel實現長按復制功能實例代碼

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

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

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

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

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

    CodingFire13652021-02-26
主站蜘蛛池模板: 一区二区三区四区在线视频 | 狠狠综合久久 | 久播播av| 午夜免费视频福利 | 国产成人免费高清激情视频 | 国产精品欧美日韩在线观看 | 日韩精品成人 | 国产黄色影视 | 亚洲一级淫片 | 免费成人高清 | 黄色av免费在线播放 | 欧美一区二区三区男人的天堂 | 久久国产电影 | 国外成人在线视频 | 成人国产精品免费观看 | 国产激情偷乱视频一区二区三区 | 午夜精品网站 | 日韩无在线 | 亚洲乱码国产乱码精品精的特点 | 黄站免费 | 亚洲精品视频网站在线观看 | av在线免费播放 | 久久久国产精品一区 | 日本久久久久久 | 综合99| 国产中文字幕在线免费观看 | 亚洲激情在线播放 | 免费一级片免费一级片 | 国产精品久久久久久久久久久久久 | 国产精品成人国产乱一区 | 亚洲精品国产精品国自产在线 | 国产一区二区精品在线观看 | 国产精品视频一二三 | 久久99精品久久久久久琪琪 | 久久免费精品国产 | 久久精品国产清自在天天线 | 午夜视频在线观看免费视频 | 久久免费的视频 | 日韩精品欧美 | 亚洲视频自拍 | 日韩免费一区二区 |