提交 cb87d1e4 编写于 作者: J Jin Wang

Demonstrated how to make element laid out differently to achieve different parallex effect.

上级 4161cac4
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="NbP-BS-4jY">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="NbP-BS-4jY">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
......@@ -32,21 +32,20 @@
<rect key="frame" x="0.0" y="0.0" width="200" height="200"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QSQ-Xq-WAm">
<rect key="frame" x="-9" y="38.5" width="218" height="123"/>
<fontDescription key="fontDescription" name="AvenirNext-UltraLight" family="Avenir Next" pointSize="90"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="8gI-El-CPc">
<rect key="frame" x="0.0" y="0.0" width="200" height="200"/>
</imageView>
</subviews>
</view>
<constraints>
<constraint firstItem="QSQ-Xq-WAm" firstAttribute="centerX" secondItem="PaF-XJ-Xcy" secondAttribute="centerX" id="9ef-xY-PkK"/>
<constraint firstItem="QSQ-Xq-WAm" firstAttribute="centerY" secondItem="PaF-XJ-Xcy" secondAttribute="centerY" id="Ka3-TZ-Uga"/>
<constraint firstAttribute="bottom" secondItem="8gI-El-CPc" secondAttribute="bottom" id="NcH-gu-whz"/>
<constraint firstAttribute="trailing" secondItem="8gI-El-CPc" secondAttribute="trailing" id="VRy-0w-Fbr"/>
<constraint firstItem="8gI-El-CPc" firstAttribute="leading" secondItem="PaF-XJ-Xcy" secondAttribute="leading" id="ZKn-R6-Jer"/>
<constraint firstItem="8gI-El-CPc" firstAttribute="top" secondItem="PaF-XJ-Xcy" secondAttribute="top" id="osF-Kr-Lhp"/>
</constraints>
<size key="customSize" width="200" height="200"/>
<connections>
<outlet property="titleLabel" destination="QSQ-Xq-WAm" id="8Vm-ea-2IG"/>
<outlet property="imageView" destination="8gI-El-CPc" id="OY3-mP-zo6"/>
</connections>
</collectionViewCell>
</cells>
......
......@@ -11,11 +11,42 @@ import AnimatedCollectionViewLayout
class SimpleCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var titleLabel: UILabel!
// @IBOutlet weak var titleLabel: UILabel!
@IBOutlet private var imageView: UIImageView!
private let titleLabel = UILabel(frame: .zero)
override func awakeFromNib() {
super.awakeFromNib()
backgroundColor = .clear
addSubview(titleLabel)
let horizontalCenterConstraint = NSLayoutConstraint(item: titleLabel,
attribute: .centerX,
relatedBy: .equal,
toItem: self,
attribute: .centerX,
multiplier: 1.0,
constant: 0)
let verticalCenterConstraint = NSLayoutConstraint(item: titleLabel,
attribute: .centerY,
relatedBy: .equal,
toItem: self,
attribute: .centerY,
multiplier: 1.0,
constant: 0)
addConstraint(horizontalCenterConstraint)
addConstraint(verticalCenterConstraint)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.font = .preferredFont(forTextStyle: .headline)
titleLabel.textColor = .white
imageView.contentMode = .scaleAspectFill
imageView.image = #imageLiteral(resourceName: "nature3")
}
func bind(color: String, imageName: String) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册