Last active
August 29, 2015 14:19
-
-
Save adriantofan/36ed1867ad1f470a14aa to your computer and use it in GitHub Desktop.
table view self sizing header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> | |
<dependencies> | |
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/> | |
</dependencies> | |
<customFonts key="customFonts"> | |
<mutableArray key="FreightSansPro-Book.otf"> | |
<string>FreightSansProBook-Regular</string> | |
</mutableArray> | |
</customFonts> | |
<objects> | |
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ProductCreateViewController"> | |
<connections> | |
<outlet property="header" destination="BIc-3s-nff" id="7kK-Rq-S7r"/> | |
<outlet property="headerContent" destination="iN0-l3-epB" id="NzA-GC-9FM"/> | |
<outlet property="headerLabel" destination="UWX-JG-lTJ" id="yNF-zg-B76"/> | |
</connections> | |
</placeholder> | |
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | |
<view clipsSubviews="YES" contentMode="scaleToFill" id="BIc-3s-nff"> | |
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | |
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | |
<subviews> | |
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iN0-l3-epB"> | |
<rect key="frame" x="0.0" y="0.0" width="600" height="54"/> | |
<subviews> | |
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Add ..." lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UWX-JG-lTJ"> | |
<rect key="frame" x="8" y="15" width="584" height="24"/> | |
<fontDescription key="fontDescription" name="FreightSansProBook-Regular" family="FreightSans Pro" pointSize="19"/> | |
<color key="textColor" red="0.28529193997383118" green="0.28533676266670227" blue="0.28527560830116272" alpha="1" colorSpace="calibratedRGB"/> | |
<nil key="highlightedColor"/> | |
</label> | |
</subviews> | |
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/> | |
<constraints> | |
<constraint firstItem="UWX-JG-lTJ" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="8" id="E2F-6d-j04"/> | |
<constraint firstAttribute="trailing" secondItem="UWX-JG-lTJ" secondAttribute="trailing" constant="8" id="GFX-Mw-LkS"/> | |
<constraint firstItem="UWX-JG-lTJ" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="15" id="KY3-t1-heO"/> | |
<constraint firstAttribute="bottom" secondItem="UWX-JG-lTJ" secondAttribute="bottom" constant="15" id="bY8-UW-XIq"/> | |
</constraints> | |
</view> | |
</subviews> | |
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | |
<constraints> | |
<constraint firstItem="iN0-l3-epB" firstAttribute="leading" secondItem="BIc-3s-nff" secondAttribute="leading" id="PyT-eZ-LYS"/> | |
<constraint firstAttribute="bottom" secondItem="iN0-l3-epB" secondAttribute="bottom" id="Y7h-TG-ESO"/> | |
<constraint firstItem="iN0-l3-epB" firstAttribute="top" secondItem="BIc-3s-nff" secondAttribute="top" id="YRR-WY-x3w"/> | |
<constraint firstAttribute="trailing" secondItem="iN0-l3-epB" secondAttribute="trailing" id="hPs-1d-Xhj"/> | |
</constraints> | |
<variation key="default"> | |
<mask key="constraints"> | |
<exclude reference="Y7h-TG-ESO"/> | |
</mask> | |
</variation> | |
<point key="canvasLocation" x="329" y="831"/> | |
</view> | |
</objects> | |
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The header contains a super view (the container) | |
// and a headerContent. The headerContent is constrained to the top of the header (no bottom!) | |
// Also headerContent has constrains to specify it's height(e.g. a label that pushes). | |
@interface ProductCreateViewController() | |
@property (strong, nonatomic) IBOutlet UIView *headerContent; | |
@property (weak, nonatomic) IBOutlet UILabel *headerLabel; | |
@property (strong, nonatomic) IBOutlet UIView *header; | |
@end | |
@implementation ProductCreateViewController | |
@dynamic viewModel; | |
-(void)viewDidLoad{ | |
[super viewDidLoad]; | |
[[NSBundle mainBundle] loadNibNamed:@"ProductCreateHeader" owner:self options:nil]; | |
self.title = NSLocalizedString(@"Create",nil); | |
self.headerLabel.text = @"asd asd aad asda dasd asd adasd asd ad asddasds dasd sadasd asda ds asd as dasd asd asd "; | |
self.tableView.tableHeaderView = self.header; | |
} | |
-(void)viewDidLayoutSubviews{ | |
[super viewDidLayoutSubviews]; | |
[self.header setNeedsLayout]; | |
[self.header layoutIfNeeded]; | |
CGFloat height = self.headerContent.frame.size.height;// adding the origin because innerHeaderView starts partway down headerView. | |
CGRect frame = self.header.frame; | |
frame.size.height = height; | |
self.header.frame = frame; | |
[self.tableView setTableHeaderView:self.header]; | |
}@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment