Skip to content

Commit

Permalink
support in the cell
Browse files Browse the repository at this point in the history
  • Loading branch information
lijingcheng committed Jul 18, 2016
1 parent faefe38 commit 2126223
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Example/JCTagListView.xcodeproj/project.pbxproj
Expand Up @@ -23,6 +23,8 @@
7D8F1BC1A8CB6A15727E3215 /* libPods-JCTagListView_Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8200F925C0382BC1AFCC5937 /* libPods-JCTagListView_Tests.a */; };
8045718C51A6AEFCA61B6A0A /* libPods-JCTagListView_Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 172ADC17AD2C20DA8DF003E7 /* libPods-JCTagListView_Example.a */; };
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
F37F854F1D3CA94F00365348 /* JCTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F37F854E1D3CA94F00365348 /* JCTableViewController.m */; };
F37F85521D3CA97000365348 /* JCTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F37F85511D3CA97000365348 /* JCTableViewCell.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -65,6 +67,10 @@
62AE6E6A39D7B32D65B93E59 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
8200F925C0382BC1AFCC5937 /* libPods-JCTagListView_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-JCTagListView_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
F37F854D1D3CA94F00365348 /* JCTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCTableViewController.h; sourceTree = "<group>"; };
F37F854E1D3CA94F00365348 /* JCTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JCTableViewController.m; sourceTree = "<group>"; };
F37F85501D3CA97000365348 /* JCTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCTableViewCell.h; sourceTree = "<group>"; };
F37F85511D3CA97000365348 /* JCTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JCTableViewCell.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -134,6 +140,10 @@
6003F59D195388D20070C39A /* JCAppDelegate.m */,
6003F5A5195388D20070C39A /* JCViewController.h */,
6003F5A6195388D20070C39A /* JCViewController.m */,
F37F854D1D3CA94F00365348 /* JCTableViewController.h */,
F37F854E1D3CA94F00365348 /* JCTableViewController.m */,
F37F85501D3CA97000365348 /* JCTableViewCell.h */,
F37F85511D3CA97000365348 /* JCTableViewCell.m */,
6003F594195388D20070C39A /* Supporting Files */,
);
name = "Example for JCTagListView";
Expand Down Expand Up @@ -358,8 +368,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F37F85521D3CA97000365348 /* JCTableViewCell.m in Sources */,
6003F59E195388D20070C39A /* JCAppDelegate.m in Sources */,
6003F5A7195388D20070C39A /* JCViewController.m in Sources */,
F37F854F1D3CA94F00365348 /* JCTableViewController.m in Sources */,
6003F59A195388D20070C39A /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
16 changes: 16 additions & 0 deletions Example/JCTagListView/JCTableViewCell.h
@@ -0,0 +1,16 @@
//
// JCTableViewCell.h
// JCTagListView
//
// Created by 李京城 on 16/7/18.
// Copyright © 2016年 lijingcheng. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "JCTagListView.h"

@interface JCTableViewCell : UITableViewCell

@property (nonatomic, copy) NSArray *tags;

@end
26 changes: 26 additions & 0 deletions Example/JCTagListView/JCTableViewCell.m
@@ -0,0 +1,26 @@
//
// JCTableViewCell.m
// JCTagListView
//
// Created by 李京城 on 16/7/18.
// Copyright © 2016年 lijingcheng. All rights reserved.
//

#import "JCTableViewCell.h"

@interface JCTableViewCell ()

@property (nonatomic, weak) IBOutlet JCTagListView *tagListView;

@end

@implementation JCTableViewCell

- (void)setTags:(NSArray *)tags
{
_tags = tags;

self.tagListView.tags = [NSMutableArray arrayWithArray:tags];
}

@end
13 changes: 13 additions & 0 deletions Example/JCTagListView/JCTableViewController.h
@@ -0,0 +1,13 @@
//
// JCTableViewController.h
// JCTagListView
//
// Created by 李京城 on 16/7/18.
// Copyright © 2016年 lijingcheng. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface JCTableViewController : UITableViewController

@end
57 changes: 57 additions & 0 deletions Example/JCTagListView/JCTableViewController.m
@@ -0,0 +1,57 @@
//
// JCTableViewController.m
// JCTagListView
//
// Created by 李京城 on 16/7/18.
// Copyright © 2016年 lijingcheng. All rights reserved.
//

#import "JCTableViewController.h"
#import "JCTableViewCell.h"
#import "JCCollectionViewTagFlowLayout.h"

@interface JCTableViewController ()

@property (nonatomic, copy) NSArray *allTags;
@property (nonatomic, strong) NSMutableArray *cellHeights;

@property (nonatomic, strong) JCCollectionViewTagFlowLayout *layout;

@end

@implementation JCTableViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.cellHeights = [NSMutableArray array];
self.layout = [[JCCollectionViewTagFlowLayout alloc] init];

self.tableView.tableFooterView = [UIView new];

self.allTags = @[@[@"NSString", @"NSMutableString", @"NSArray", @"UIAlertView", @"UITapGestureRecognizer", @"IBOutlet", @"IBAction", @"id", @"UIView", @"UIStatusBar", @"UITableViewController", @"UIStepper", @"UISegmentedControl", @"UICollectionViewController", @"UISearchBar", @"UIToolbar", @"UIPageControl"], @[@"UIActionSheet", @"NSMutableArray", @"NSDictionary", @"NSMutableDictionary", @"NSSet", @"NSMutableSet", @"NSData", @"NSMutableData", @"NSDate", @"UICollectionView", @"UIViewController", @"NSCalendar"], @[@"UITextField", @"UITextView", @"UIImageView", @"UITableView"], @[@"UIButton", @"UILabel"]];

for (NSArray *tags in self.allTags) {
[self.cellHeights addObject:@([self.layout calculateContentHeight:tags])];
}
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.allTags.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self.cellHeights[indexPath.row] floatValue];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
JCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
cell.tags = self.allTags[indexPath.row];

return cell;
}

@end
5 changes: 5 additions & 0 deletions Example/JCTagListView/JCViewController.m
Expand Up @@ -8,6 +8,7 @@

#import "JCViewController.h"
#import "JCTagListView.h"
#import "JCTableViewController.h"

@interface JCViewController ()

Expand Down Expand Up @@ -44,6 +45,10 @@ - (IBAction)delete:(id)sender
[self.tagListView.selectedTags removeAllObjects];

[self.tagListView.collectionView reloadData];

JCTableViewController *tableVC = [self.storyboard instantiateViewControllerWithIdentifier:@"JCTableViewController"];

[self.navigationController pushViewController:tableVC animated:YES];
}

@end
50 changes: 45 additions & 5 deletions Example/JCTagListView/Main.storyboard
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="tXg-JF-3Hi">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="tXg-JF-3Hi">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand All @@ -12,7 +12,6 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="U5Y-Jy-mcc">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</navigationBar>
<connections>
<segue destination="whP-gf-Uak" kind="relationship" relationship="rootViewController" id="LTY-Yc-OXT"/>
Expand All @@ -36,11 +35,9 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UNz-gg-734" customClass="JCTagListView">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Mvr-aV-6Um" firstAttribute="top" secondItem="UNz-gg-734" secondAttribute="bottom" id="KeM-3L-LHZ"/>
Expand All @@ -64,6 +61,49 @@
</objects>
<point key="canvasLocation" x="185" y="453"/>
</scene>
<!--Table View Controller-->
<scene sceneID="ic0-WD-tho">
<objects>
<tableViewController storyboardIdentifier="JCTableViewController" id="U23-N7-vNa" customClass="JCTableViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="LZ2-Cs-KP5">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="cellId" id="hch-gG-zQZ" customClass="JCTableViewCell">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hch-gG-zQZ" id="Ycz-5p-rBR">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Fwo-Ua-FJX" customClass="JCTagListView">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="Fwo-Ua-FJX" secondAttribute="trailing" id="AVS-mB-L0o"/>
<constraint firstAttribute="bottom" secondItem="Fwo-Ua-FJX" secondAttribute="bottom" constant="0.5" id="Fbu-iH-3G5"/>
<constraint firstItem="Fwo-Ua-FJX" firstAttribute="leading" secondItem="Ycz-5p-rBR" secondAttribute="leading" id="ayy-EO-opd"/>
<constraint firstItem="Fwo-Ua-FJX" firstAttribute="top" secondItem="Ycz-5p-rBR" secondAttribute="top" id="k8M-ew-oGw"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="tagListView" destination="Fwo-Ua-FJX" id="2Ih-pM-2pJ"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="U23-N7-vNa" id="ZIu-W2-6pj"/>
<outlet property="delegate" destination="U23-N7-vNa" id="oN8-2w-ev7"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ngm-sW-PFs" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="840" y="453"/>
</scene>
</scenes>
<resources>
<image name="delete" width="24" height="24"/>
Expand Down
2 changes: 1 addition & 1 deletion JCTagListView.podspec
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "JCTagListView"
s.version = "0.0.9"
s.version = "0.1.0"
s.summary = "Support delete tags and settings tags color."
s.homepage = "http://lijingcheng.github.io/"
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
Expand Down
2 changes: 2 additions & 0 deletions Pod/Classes/JCCollectionViewTagFlowLayout.h
Expand Up @@ -10,4 +10,6 @@

@interface JCCollectionViewTagFlowLayout : UICollectionViewFlowLayout

- (CGFloat)calculateContentHeight:(NSArray *)tags;

@end
29 changes: 29 additions & 0 deletions Pod/Classes/JCCollectionViewTagFlowLayout.m
Expand Up @@ -128,4 +128,33 @@ - (CGSize)itemSizeForIndexPath:(NSIndexPath *)indexPath
return self.itemSize;
}

- (CGFloat)calculateContentHeight:(NSArray *)tags
{
CGFloat contentHeight = self.sectionInset.top + self.itemSize.height;

CGFloat originX = self.sectionInset.left;
CGFloat originY = self.sectionInset.top;

for (NSInteger i = 0; i < tags.count; i++) {
CGSize maxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - self.sectionInset.left - self.sectionInset.right, self.itemSize.height);

CGRect frame = [tags[i] boundingRectWithSize:maxSize options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0f]} context:nil];

CGSize itemSize = CGSizeMake(frame.size.width + 20.0f, self.itemSize.height);

if ((originX + itemSize.width + self.sectionInset.right/2) > [UIScreen mainScreen].bounds.size.width) {
originX = self.sectionInset.left;
originY += itemSize.height + self.minimumLineSpacing;

contentHeight += itemSize.height + self.minimumLineSpacing;
}

originX += itemSize.width + self.minimumInteritemSpacing;
}

contentHeight += self.sectionInset.bottom;

return contentHeight;
}

@end
1 change: 1 addition & 0 deletions Pod/Classes/JCTagListView.m
Expand Up @@ -62,6 +62,7 @@ - (void)setup
_collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.scrollEnabled = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.backgroundColor = [UIColor clearColor];
Expand Down

0 comments on commit 2126223

Please sign in to comment.