Skip to content

Commit

Permalink
Change the example of working with UITableViewCell
Browse files Browse the repository at this point in the history
  • Loading branch information
zsk425 committed Apr 19, 2015
1 parent f42d5d4 commit ecc2818
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 28 deletions.
8 changes: 4 additions & 4 deletions WrapViewWithAutolayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@
682ABA721A36933300D57A1A /* AppDelegate.m */,
682ABA741A36933300D57A1A /* ViewController.h */,
682ABA751A36933300D57A1A /* ViewController.m */,
682ABA771A36933300D57A1A /* Main.storyboard */,
682ABA7C1A36933300D57A1A /* LaunchScreen.xib */,
682ABA7A1A36933300D57A1A /* Images.xcassets */,
682ABA6D1A36933300D57A1A /* Supporting Files */,
D865CB901A6415B200F3592C /* TagsTableViewController.h */,
D865CB911A6415B200F3592C /* TagsTableViewController.m */,
D865CB931A64160500F3592C /* TagsTableCell.h */,
D865CB941A64160500F3592C /* TagsTableCell.m */,
682ABA771A36933300D57A1A /* Main.storyboard */,
682ABA7C1A36933300D57A1A /* LaunchScreen.xib */,
682ABA7A1A36933300D57A1A /* Images.xcassets */,
682ABA6D1A36933300D57A1A /* Supporting Files */,
);
path = WrapViewWithAutolayout;
sourceTree = "<group>";
Expand Down
43 changes: 41 additions & 2 deletions WrapViewWithAutolayout/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down Expand Up @@ -138,6 +138,7 @@
</tableViewCellContentView>
<connections>
<outlet property="tagView" destination="xsy-ND-UuT" id="flf-6f-XWB"/>
<segue destination="FYb-7w-VlF" kind="show" id="6fh-tu-8Tl"/>
</connections>
</tableViewCell>
</prototypes>
Expand All @@ -146,9 +147,47 @@
<outlet property="delegate" destination="FbG-4l-pGh" id="WQc-dz-8cY"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="jr3-G9-XvO"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Iv9-aI-L7R" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1464" y="792"/>
</scene>
<!--Detail-->
<scene sceneID="JYJ-4n-3cQ">
<objects>
<viewController id="FYb-7w-VlF" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="iTo-Lk-xL1"/>
<viewControllerLayoutGuide type="bottom" id="ZfB-s6-959"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="LGE-qp-0iD">
<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"/>
</view>
<navigationItem key="navigationItem" title="Detail" id="juj-Ko-kcc"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="au1-aJ-CPJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2217" y="792"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="2hU-vW-zdv">
<objects>
<navigationController storyboardIdentifier="TableNV" automaticallyAdjustsScrollViewInsets="NO" id="KA0-I5-dTs" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Q4L-7C-Az2">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="FbG-4l-pGh" kind="relationship" relationship="rootViewController" id="WmG-Su-QWS"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Oiq-x4-I7A" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="652" y="792"/>
</scene>
</scenes>
Expand Down
10 changes: 0 additions & 10 deletions WrapViewWithAutolayout/TagsTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,4 @@

@implementation TagsTableCell

- (void)awakeFromNib {
// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

@end
47 changes: 37 additions & 10 deletions WrapViewWithAutolayout/TagsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "TagsTableViewController.h"
#import "TagsTableCell.h"
#import "SKTag.h"
#import "SKTagView.h"
#import <HexColors/HexColor.h>

Expand All @@ -17,13 +16,19 @@
//Cell
static NSString *const kTagsTableCellReuseIdentifier = @"TagsTableCell";


@interface UIImage (SKTagView)
+ (UIImage *)imageWithColor:(UIColor *)color;
@end

@interface TagsTableViewController ()
@property (nonatomic, strong) NSArray *colorPool;
@end

@implementation TagsTableViewController

- (void)viewDidLoad {
- (void)viewDidLoad
{
[super viewDidLoad];

self.colorPool = @[@"#7ecef4", @"#84ccc9", @"#88abda",@"#7dc1dd",@"#b6b8de"];
Expand All @@ -32,12 +37,8 @@ - (void)viewDidLoad {
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}

Expand All @@ -57,8 +58,9 @@ - (void)configureCell:(TagsTableCell *)cell atIndexPath:(NSIndexPath *)indexPath
tag.textColor = [UIColor whiteColor];
tag.fontSize = 15;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgColor = [UIColor colorWithHexString:self.colorPool[idx % self.colorPool.count]];
tag.bgImg = [UIImage imageWithColor:[UIColor colorWithHexString:self.colorPool[idx % self.colorPool.count]]];
tag.cornerRadius = 5;
tag.enable = NO;

[cell.tagView addTag:tag];
}];
Expand All @@ -75,18 +77,43 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
TagsTableCell *cell = nil;
if (!cell) {
if (!cell)
{
cell = [tableView dequeueReusableCellWithIdentifier:kTagsTableCellReuseIdentifier];
}

[self configureCell:cell atIndexPath:indexPath];
return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - User interactions
- (void)handleBtn:(id)sender
{
NSLog(@"Tapped me");
}

@end

@implementation UIImage (SKTagView)

+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

@end
4 changes: 2 additions & 2 deletions WrapViewWithAutolayout/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "ViewController.h"
#import "SKTag.h"
#import "SKTagView.h"
#import <Masonry/Masonry.h>
#import <HexColors/HexColor.h>
Expand All @@ -21,7 +20,8 @@ @interface ViewController ()

@implementation ViewController

- (void)viewDidLoad {
- (void)viewDidLoad
{
[super viewDidLoad];

self.colorPool = @[@"#7ecef4", @"#84ccc9", @"#88abda",@"#7dc1dd",@"#b6b8de"];
Expand Down

0 comments on commit ecc2818

Please sign in to comment.