Skip to content

Commit aa000f6

Browse files
author
Bluelich
committedSep 26, 2019
update demo for lib
1 parent b37756d commit aa000f6

File tree

3 files changed

+167
-21
lines changed

3 files changed

+167
-21
lines changed
 

‎Example/BLCollectionViewTagLayout/BLViewController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
@import UIKit;
1010

11-
@interface BLViewController : UIViewController
11+
@interface BLViewController : UICollectionViewController
1212

1313
@end

‎Example/BLCollectionViewTagLayout/BLViewController.m

+72-6
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,89 @@
77
//
88

99
#import "BLViewController.h"
10+
#import <BLCollectionViewTagLayout.h>
1011

1112
@interface BLViewController ()
1213

1314
@end
1415

1516
@implementation BLViewController
1617

17-
- (void)viewDidLoad
18-
{
18+
- (void)viewDidLoad {
1919
[super viewDidLoad];
20-
// Do any additional setup after loading the view, typically from a nib.
20+
self.clearsSelectionOnViewWillAppear = NO;
21+
self.collectionView.contentInset = UIEdgeInsetsMake(44, 44, 44, 44);
22+
self.collectionView.backgroundColor = UIColor.redColor;
23+
self.view.backgroundColor = UIColor.blueColor;
24+
self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(14, 0, 14, 0);
25+
[(BLCollectionViewTagLayout *)self.collectionViewLayout autoConfigSystemAdditionalAdjustedContentInsetWith:UIApplication.sharedApplication.statusBarFrame navigationBar:self.navigationController.navigationBar tabbar:self.tabBarController.tabBar];
26+
[self.collectionView registerClass:UICollectionReusableView.class
27+
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:UICollectionElementKindSectionHeader];
28+
[self.collectionView registerClass:UICollectionReusableView.class
29+
forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:UICollectionElementKindSectionFooter];
30+
self.collectionView.contentOffset = CGPointZero;
31+
}
32+
- (void)flashScrollIndicators
33+
{
34+
[self.collectionView flashScrollIndicators];
2135
}
36+
#pragma mark <UICollectionViewDataSource>
2237

23-
- (void)didReceiveMemoryWarning
38+
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
39+
{
40+
return 10;
41+
}
42+
43+
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
44+
return 10;
45+
}
46+
47+
static NSInteger const labelTag = 1000;
48+
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
49+
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
50+
UILabel *label = [cell.contentView viewWithTag:labelTag];
51+
if (!label) {
52+
label = [UILabel new];
53+
label.tag = labelTag;
54+
label.numberOfLines = 0;
55+
[cell.contentView addSubview:label];
56+
label.translatesAutoresizingMaskIntoConstraints = NO;
57+
[label.centerXAnchor constraintEqualToAnchor:cell.contentView.centerXAnchor].active = YES;
58+
[label.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor].active = YES;
59+
}
60+
label.text = [NSString stringWithFormat:@"section:%ld\nitem:%ld",indexPath.section,indexPath.item];
61+
cell.backgroundColor = UIColor.lightGrayColor;
62+
return cell;
63+
}
64+
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
65+
{
66+
UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kind forIndexPath:indexPath];
67+
UILabel *label = [view viewWithTag:1000];
68+
if (!label) {
69+
label = [UILabel new];
70+
label.tag = 1000;
71+
label.numberOfLines = 0;
72+
[view addSubview:label];
73+
label.translatesAutoresizingMaskIntoConstraints = NO;
74+
[label.leftAnchor constraintEqualToAnchor:view.leftAnchor].active = YES;
75+
[label.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = YES;
76+
}
77+
NSString *string = [kind stringByReplacingOccurrencesOfString:@"UICollectionElementKindSection" withString:@""];
78+
label.text = [NSString stringWithFormat:@"%@\nsection:%ld",string,indexPath.section];
79+
view.backgroundColor = UIColor.greenColor;
80+
if (kind == UICollectionElementKindSectionHeader) {
81+
view.backgroundColor = UIColor.brownColor;
82+
}
83+
return view;
84+
}
85+
#pragma mark UICollectionViewDelegateTagStyleLayout
86+
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(BLCollectionViewTagLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
87+
{
88+
return CGSizeMake(80 + indexPath.item * (indexPath.section + 5), collectionViewLayout.itemSize.height);
89+
}
90+
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(BLCollectionViewTagLayout *)collectionViewLayout insetForSection:(NSInteger)section
2491
{
25-
[super didReceiveMemoryWarning];
26-
// Dispose of any resources that can be recreated.
92+
return UIEdgeInsetsMake(50, section, 50, section);
2793
}
2894

2995
@end
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,111 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="whP-gf-Uak">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="VsR-TD-99f">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<scenes>
1212
<!--View Controller-->
13-
<scene sceneID="wQg-tq-qST">
13+
<scene sceneID="cog-Wt-WEy">
1414
<objects>
15-
<viewController id="whP-gf-Uak" customClass="BLViewController" sceneMemberID="viewController">
16-
<layoutGuides>
17-
<viewControllerLayoutGuide type="top" id="uEw-UM-LJ8"/>
18-
<viewControllerLayoutGuide type="bottom" id="Mvr-aV-6Um"/>
19-
</layoutGuides>
20-
<view key="view" contentMode="scaleToFill" id="TpU-gO-2f1">
15+
<collectionViewController id="Svu-6j-u4A" customClass="BLViewController" sceneMemberID="viewController">
16+
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="0tE-vU-DvN">
2117
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2218
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23-
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
24-
</view>
25-
</viewController>
26-
<placeholder placeholderIdentifier="IBFirstResponder" id="tc2-Qw-aMS" userLabel="First Responder" sceneMemberID="firstResponder"/>
19+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
20+
<collectionViewLayout key="collectionViewLayout" id="VmD-ZO-9JT" customClass="BLCollectionViewTagLayout">
21+
<userDefinedRuntimeAttributes>
22+
<userDefinedRuntimeAttribute type="size" keyPath="itemSize">
23+
<size key="value" width="100" height="100"/>
24+
</userDefinedRuntimeAttribute>
25+
<userDefinedRuntimeAttribute type="number" keyPath="sectionTop">
26+
<real key="value" value="10"/>
27+
</userDefinedRuntimeAttribute>
28+
<userDefinedRuntimeAttribute type="number" keyPath="sectionLeft">
29+
<real key="value" value="10"/>
30+
</userDefinedRuntimeAttribute>
31+
<userDefinedRuntimeAttribute type="number" keyPath="sectionBottom">
32+
<real key="value" value="10"/>
33+
</userDefinedRuntimeAttribute>
34+
<userDefinedRuntimeAttribute type="number" keyPath="sectionRight">
35+
<real key="value" value="10"/>
36+
</userDefinedRuntimeAttribute>
37+
<userDefinedRuntimeAttribute type="number" keyPath="lineSpacing">
38+
<real key="value" value="10"/>
39+
</userDefinedRuntimeAttribute>
40+
<userDefinedRuntimeAttribute type="number" keyPath="itemSpacing">
41+
<real key="value" value="10"/>
42+
</userDefinedRuntimeAttribute>
43+
<userDefinedRuntimeAttribute type="size" keyPath="headerSize">
44+
<size key="value" width="0.0" height="44"/>
45+
</userDefinedRuntimeAttribute>
46+
<userDefinedRuntimeAttribute type="size" keyPath="footerSize">
47+
<size key="value" width="0.0" height="44"/>
48+
</userDefinedRuntimeAttribute>
49+
<userDefinedRuntimeAttribute type="boolean" keyPath="pinHeaders" value="YES"/>
50+
<userDefinedRuntimeAttribute type="boolean" keyPath="pinFooters" value="YES"/>
51+
</userDefinedRuntimeAttributes>
52+
</collectionViewLayout>
53+
<cells>
54+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="xns-wY-ASO">
55+
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
56+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
57+
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
58+
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
59+
<autoresizingMask key="autoresizingMask"/>
60+
</view>
61+
</collectionViewCell>
62+
</cells>
63+
<connections>
64+
<outlet property="dataSource" destination="Svu-6j-u4A" id="cpp-W8-mFo"/>
65+
<outlet property="delegate" destination="Svu-6j-u4A" id="l7N-vb-PuP"/>
66+
</connections>
67+
</collectionView>
68+
<navigationItem key="navigationItem" id="gJ6-Qm-6rx"/>
69+
</collectionViewController>
70+
<placeholder placeholderIdentifier="IBFirstResponder" id="ysT-Q3-KCQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
2771
</objects>
28-
<point key="canvasLocation" x="305" y="433"/>
72+
<point key="canvasLocation" x="2106.4000000000001" y="369.26536731634184"/>
73+
</scene>
74+
<!--Item-->
75+
<scene sceneID="dBQ-WO-krA">
76+
<objects>
77+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="GSV-sP-0ER" sceneMemberID="viewController">
78+
<tabBarItem key="tabBarItem" title="Item" id="QiU-m8-9vh"/>
79+
<toolbarItems/>
80+
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="jIV-2O-4yO">
81+
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
82+
<autoresizingMask key="autoresizingMask"/>
83+
</navigationBar>
84+
<nil name="viewControllers"/>
85+
<connections>
86+
<segue destination="Svu-6j-u4A" kind="relationship" relationship="rootViewController" id="XcI-jW-hbv"/>
87+
</connections>
88+
</navigationController>
89+
<placeholder placeholderIdentifier="IBFirstResponder" id="S7a-p3-gtl" userLabel="First Responder" sceneMemberID="firstResponder"/>
90+
</objects>
91+
<point key="canvasLocation" x="1167.2" y="369.26536731634184"/>
92+
</scene>
93+
<!--Tab Bar Controller-->
94+
<scene sceneID="eUQ-l4-iSH">
95+
<objects>
96+
<tabBarController automaticallyAdjustsScrollViewInsets="NO" id="VsR-TD-99f" sceneMemberID="viewController">
97+
<toolbarItems/>
98+
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="8Lz-20-UQQ">
99+
<autoresizingMask key="autoresizingMask"/>
100+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
101+
</tabBar>
102+
<connections>
103+
<segue destination="GSV-sP-0ER" kind="relationship" relationship="viewControllers" id="XEu-Ys-1pW"/>
104+
</connections>
105+
</tabBarController>
106+
<placeholder placeholderIdentifier="IBFirstResponder" id="jAv-wg-btv" userLabel="First Responder" sceneMemberID="firstResponder"/>
107+
</objects>
108+
<point key="canvasLocation" x="228" y="369.26536731634184"/>
29109
</scene>
30110
</scenes>
31111
</document>

0 commit comments

Comments
 (0)