Skip to content

Commit

Permalink
Remove Autolayout inside SKTagView
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaokang Zhao committed Feb 14, 2016
1 parent 1baec5c commit 951d286
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 156 deletions.
63 changes: 30 additions & 33 deletions Classes/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E17e" 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="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -16,6 +17,21 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Index:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="t7U-Ia-bLd">
<rect key="frame" x="16" y="485" width="41.5" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.44313725490196076" green="0.44313725490196076" blue="0.44313725490196076" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="0" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Q33-2Y-lMM">
<rect key="frame" x="65" y="479" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="Uf7-fG-zZF"/>
</constraints>
<color key="textColor" red="0.44313725490196076" green="0.44313725490196076" blue="0.44313725490196076" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" keyboardType="numberPad"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Be7-f3-ZyA">
<rect key="frame" x="16" y="530" width="60" height="30"/>
<constraints>
Expand All @@ -29,7 +45,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="io1-TE-I9C">
<rect key="frame" x="101" y="530" width="60" height="30"/>
<rect key="frame" x="270" y="530" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="Kq2-EH-d4c"/>
</constraints>
Expand All @@ -40,32 +56,8 @@
<action selector="onInsert:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="cIP-vB-HTP"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Index:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="t7U-Ia-bLd">
<rect key="frame" x="16" y="485" width="43" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.44313725490196076" green="0.44313725490196076" blue="0.44313725490196076" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="0" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Q33-2Y-lMM">
<rect key="frame" x="66" y="479" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="Uf7-fG-zZF"/>
</constraints>
<color key="textColor" red="0.44313725490196076" green="0.44313725490196076" blue="0.44313725490196076" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" keyboardType="numberPad"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1SV-KH-g5i">
<rect key="frame" x="514" y="530" width="78" height="30"/>
<state key="normal" title="Remove All">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onRemoveAll:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="ehl-67-qoZ"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hgs-nh-fvM">
<rect key="frame" x="429" y="530" width="60" height="30"/>
<rect key="frame" x="520" y="530" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="MFl-wp-oDo"/>
</constraints>
Expand All @@ -80,18 +72,16 @@
<color key="backgroundColor" red="0.92941176469999998" green="0.92941176469999998" blue="0.92941176469999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="io1-TE-I9C" firstAttribute="leading" secondItem="Be7-f3-ZyA" secondAttribute="trailing" constant="25" id="82V-kc-Hrm"/>
<constraint firstItem="Q33-2Y-lMM" firstAttribute="leading" secondItem="t7U-Ia-bLd" secondAttribute="trailing" constant="7.5" id="9gj-3P-iRd"/>
<constraint firstItem="t7U-Ia-bLd" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="16" id="ERn-Tq-BK9"/>
<constraint firstItem="1SV-KH-g5i" firstAttribute="centerY" secondItem="hgs-nh-fvM" secondAttribute="centerY" id="MKC-Qu-vU5"/>
<constraint firstItem="hgs-nh-fvM" firstAttribute="centerY" secondItem="Be7-f3-ZyA" secondAttribute="centerY" id="FnR-OR-r5d"/>
<constraint firstItem="io1-TE-I9C" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="JdL-Jx-pfR"/>
<constraint firstItem="io1-TE-I9C" firstAttribute="centerY" secondItem="Be7-f3-ZyA" secondAttribute="centerY" id="MTW-Pa-Or1"/>
<constraint firstAttribute="bottom" secondItem="t7U-Ia-bLd" secondAttribute="bottom" constant="97" id="Ma3-M4-z7h"/>
<constraint firstAttribute="trailing" secondItem="hgs-nh-fvM" secondAttribute="trailing" constant="20" id="YAk-WI-95W"/>
<constraint firstItem="t7U-Ia-bLd" firstAttribute="centerY" secondItem="Q33-2Y-lMM" secondAttribute="centerY" id="bwC-CH-e64"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="1SV-KH-g5i" secondAttribute="bottom" constant="40" id="k0H-iP-IeF"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="Be7-f3-ZyA" secondAttribute="bottom" constant="40" id="rMS-bS-fsk"/>
<constraint firstItem="Be7-f3-ZyA" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="16" id="rtJ-Gm-EyR"/>
<constraint firstAttribute="trailing" secondItem="1SV-KH-g5i" secondAttribute="trailing" constant="8" id="v1m-ic-odp"/>
<constraint firstItem="1SV-KH-g5i" firstAttribute="leading" secondItem="hgs-nh-fvM" secondAttribute="trailing" constant="25" id="zmN-uV-1V6"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="Q6V-Q8-6rY" appends="YES" id="y1T-eg-j2U"/>
Expand All @@ -118,10 +108,17 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.92941176469999998" green="0.92941176469999998" blue="0.92941176469999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<view key="tableFooterView" contentMode="scaleToFill" id="4yZ-QU-cV5" userLabel="Footer">
<rect key="frame" x="0.0" y="130" width="600" height="0.0"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="TagsTableCell" id="m3R-h8-kmN" customClass="TagsTableCell">
<rect key="frame" x="0.0" y="86" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="m3R-h8-kmN" id="nn6-mE-tbH">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xsy-ND-UuT" customClass="SKTagView">
Expand Down
46 changes: 32 additions & 14 deletions Classes/TagsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ @interface TagsTableViewController ()

@implementation TagsTableViewController

#pragma mark - Lifecycle

- (void)viewDidLoad {
[super viewDidLoad];

self.colors = @[@"#7ecef4", @"#84ccc9", @"#88abda", @"#7dc1dd", @"#b6b8de"];
self.tableView.tableFooterView = [UIView new];
}

#pragma mark - UITableViewDataSource
#pragma mark - Private

- (void)configureCell: (TagsTableCell *)cell atIndexPath: (NSIndexPath *)indexPath {
cell.tagView.preferredMaxLayoutWidth = SCREEN_WIDTH;
cell.tagView.padding = UIEdgeInsetsMake(12, 12, 12, 12);
Expand All @@ -44,27 +46,41 @@ - (void)configureCell: (TagsTableCell *)cell atIndexPath: (NSIndexPath *)indexPa

//Add Tags
[@[@"Python", @"Javascript", @"Swift", @"Go", @"Objective-C",@"C", @"PHP"] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
SKTag *tag = [SKTag tagWithText:obj];
tag.textColor = [UIColor whiteColor];
tag.fontSize = 15;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgImg = [UIImage imageWithColor: [UIColor hx_colorWithHexString: self.colors[idx % self.colors.count]]];
tag.cornerRadius = 5;
tag.enable = NO;
[cell.tagView addTag:tag];
}];
SKTag *tag = [SKTag tagWithText:obj];
tag.textColor = [UIColor whiteColor];
tag.fontSize = 15;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgImg = [UIImage imageWithColor: [UIColor hx_colorWithHexString: self.colors[idx % self.colors.count]]];
tag.cornerRadius = 5;
tag.enable = NO;

[cell.tagView addTag:tag];
}];
}


#pragma mark - UITableViewDataSource

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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TagsTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kTagsTableCellReuseIdentifier forIndexPath:indexPath];
[self configureCell: cell atIndexPath:indexPath];
return cell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath {
TagsTableCell *cell = [tableView dequeueReusableCellWithIdentifier: kTagsTableCellReuseIdentifier forIndexPath: indexPath];
static TagsTableCell *cell = nil;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cell = [tableView dequeueReusableCellWithIdentifier: kTagsTableCellReuseIdentifier];
});
[self configureCell: cell atIndexPath: indexPath];
return [cell.contentView systemLayoutSizeFittingSize: UILayoutFittingCompressedSize].height + 1;
}
Expand All @@ -73,10 +89,12 @@ - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPat
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}

#pragma mark - User interactions
#pragma mark - IBActions

- (void)handleBtn:(id)sender {
NSLog(@"Tap");
}

@end

@implementation UIImage (SKTagView)
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ - (IBAction)onRemove: (id)sender {
[self.tagView removeTagAtIndex: self.index.text.integerValue];
}

- (IBAction)onRemoveAll: (id)sender {
[self.tagView removeAllTags];
}

- (IBAction)onTapBg: (id)sender {
[self.view endEditing: YES];
}
Expand Down
3 changes: 0 additions & 3 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"

source 'https://github.com/CocoaPods/Specs.git'
inhibit_all_warnings!

Expand Down
1 change: 0 additions & 1 deletion SKTagView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ Pod::Spec.new do |s|
s.source_files = "SKTagView/*"
s.framework = "UIKit", "Foundation"
s.requires_arc = true
s.dependency "Masonry"

end
8 changes: 5 additions & 3 deletions SKTagView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
682ABA611A36933300D57A1A = {
isa = PBXGroup;
children = (
CB3B6CFF1A5E27C9008911FF /* SKTagView */,
682ABA6C1A36933300D57A1A /* Classes */,
682ABA861A36933300D57A1A /* SKTagViewTests */,
682ABA6B1A36933300D57A1A /* Products */,
Expand All @@ -103,7 +104,6 @@
682ABA6C1A36933300D57A1A /* Classes */ = {
isa = PBXGroup;
children = (
CB3B6CFF1A5E27C9008911FF /* SKTagView */,
682ABA711A36933300D57A1A /* AppDelegate.h */,
682ABA721A36933300D57A1A /* AppDelegate.m */,
682ABA741A36933300D57A1A /* ViewController.h */,
Expand Down Expand Up @@ -165,8 +165,7 @@
E1988DC652E4B5A7DD3FC44D /* SKTagButton.m */,
E19884C2F2577114719748BD /* SKTagButton.h */,
);
name = SKTagView;
path = ../SKTagView;
path = SKTagView;
sourceTree = "<group>";
};
E9B8B9417B704821F5FF7698 /* Frameworks */ = {
Expand Down Expand Up @@ -229,6 +228,7 @@
TargetAttributes = {
682ABA691A36933300D57A1A = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = Z59GEMSQ7R;
};
682ABA821A36933300D57A1A = {
CreatedOnToolsVersion = 6.0;
Expand Down Expand Up @@ -459,6 +459,7 @@
baseConfigurationReference = 6E4B93550F83909B378F1930 /* Pods-SKTagView.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = Classes/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.coloshine.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -472,6 +473,7 @@
baseConfigurationReference = 34A8B7A699E830DE1102943F /* Pods-SKTagView.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = Classes/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.coloshine.$(PRODUCT_NAME:rfc1034identifier)";
Expand Down
2 changes: 2 additions & 0 deletions SKTagView/SKTagButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@

@class SKTag;
@interface SKTagButton: UIButton

+ (nonnull instancetype)buttonWithTag: (nonnull SKTag *)tag;

@end
Loading

0 comments on commit 951d286

Please sign in to comment.