Skip to content

Added a Nib based UITableViewCell #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions TableViewCellWithAutoLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */; };
5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */; };
99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; };
99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */; };
99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; };
Expand Down Expand Up @@ -35,6 +37,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
5A3B25351945F89500838EF4 /* NibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibTableViewCell.swift; sourceTree = "<group>"; };
5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NibTableViewCell.xib; sourceTree = "<group>"; };
99BCDCA118008C0000B8E66B /* TableViewCellWithAutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TableViewCellWithAutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; };
99BCDCA418008C0000B8E66B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
99BCDCA618008C0000B8E66B /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -158,6 +162,8 @@
A7F5DDAB19440B7B008E238B /* Model.swift */,
A7C103211943F73D006A9720 /* TableViewCell.swift */,
A7F5DDAD194417DC008E238B /* TableViewController.swift */,
5A3B25351945F89500838EF4 /* NibTableViewCell.swift */,
5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */,
);
path = TableViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -216,7 +222,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = RJ;
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = RobotJackalope;
TargetAttributes = {
99BCDCBB18008C0000B8E66B = {
Expand Down Expand Up @@ -248,6 +254,7 @@
buildActionMask = 2147483647;
files = (
99BCDCAF18008C0000B8E66B /* InfoPlist.strings in Resources */,
5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */,
99BCDCB718008C0000B8E66B /* Images.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -268,6 +275,7 @@
buildActionMask = 2147483647;
files = (
B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */,
5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */,
A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */,
A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */,
A7F5DDAC19440B7B008E238B /* Model.swift in Sources */,
Expand Down Expand Up @@ -317,7 +325,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -357,7 +364,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -425,7 +431,6 @@
99BCDCD118008C0000B8E66B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
Expand All @@ -448,7 +453,6 @@
99BCDCD218008C0000B8E66B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// NibTableViewCell.swift
// TableViewCellWithAutoLayout
//
// Created by Morten Bøgh on 09/06/14.
// Copyright (c) 2014 RobotJackalope. All rights reserved.
//

import UIKit

class NibTableViewCell: UITableViewCell
{
@IBOutlet var titleLabel : UILabel
@IBOutlet var bodyLabel : UILabel

override func awakeFromNib()
{
super.awakeFromNib()
updateFonts()
}

func updateFonts()
{
titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" ambiguous="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CellIdentifier" rowHeight="75" id="Y7n-L6-IzP" customClass="NibTableViewCell" customModule="TableViewCellWithAutoLayout" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="75"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Y7n-L6-IzP" id="2eC-KE-sJB">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="1000" placeholderIntrinsicWidth="290" placeholderIntrinsicHeight="20" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="e34-1u-xXd">
<rect key="frame" x="15" y="10" width="290" height="20"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="1" alpha="0.10000000000000001" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="1000" placeholderIntrinsicWidth="290" placeholderIntrinsicHeight="14" text="Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="290" translatesAutoresizingMaskIntoConstraints="NO" id="Yui-Bi-iHF">
<rect key="frame" x="15" y="50" width="290" height="14"/>
<color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="0.10000000000000001" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption2"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.0" green="1" blue="0.0" alpha="0.10000000000000001" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="e34-1u-xXd" firstAttribute="top" secondItem="2eC-KE-sJB" secondAttribute="top" constant="10" id="1E0-WD-A4c"/>
<constraint firstItem="Yui-Bi-iHF" firstAttribute="top" relation="greaterThanOrEqual" secondItem="e34-1u-xXd" secondAttribute="bottom" constant="10" id="OpD-Xj-NIW"/>
<constraint firstItem="e34-1u-xXd" firstAttribute="leading" secondItem="2eC-KE-sJB" secondAttribute="leading" constant="15" id="Zx5-eL-3o4"/>
<constraint firstAttribute="bottom" secondItem="Yui-Bi-iHF" secondAttribute="bottom" constant="10" id="aSL-wR-GoJ"/>
<constraint firstAttribute="trailing" secondItem="Yui-Bi-iHF" secondAttribute="trailing" constant="15" id="hMY-NY-o4w"/>
<constraint firstAttribute="trailing" secondItem="e34-1u-xXd" secondAttribute="trailing" constant="15" id="jRY-6O-qcD"/>
<constraint firstItem="Yui-Bi-iHF" firstAttribute="leading" secondItem="2eC-KE-sJB" secondAttribute="leading" constant="15" id="mIC-l6-1u1"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="bodyLabel" destination="Yui-Bi-iHF" id="acr-ge-qlW"/>
<outlet property="titleLabel" destination="e34-1u-xXd" id="9WJ-z8-rg8"/>
</connections>
<point key="canvasLocation" x="426" y="435.5"/>
</tableViewCell>
</objects>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TableViewCell: UITableViewCell
contentView.addSubview(titleLabel)
contentView.addSubview(bodyLabel)

contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light red
contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light green

updateFonts()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class TableViewController : UITableViewController

tableView.allowsSelection = false

// Select either a programatically created cell or a nib-based one.
tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier)
// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier)

// Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension
tableView.rowHeight = UITableViewAutomaticDimension
Expand Down