Skip to content

Commit fc80cf3

Browse files
committed
✏️ Support iOS < 9.0
1 parent 875f0b9 commit fc80cf3

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

PhotoCollectionDemo/PhotoCollectionDemo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
buildSettings = {
278278
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
279279
INFOPLIST_FILE = PhotoCollectionDemo/Info.plist;
280+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
280281
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
281282
PRODUCT_BUNDLE_IDENTIFIER = luantran.PhotoCollectionDemo;
282283
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -289,6 +290,7 @@
289290
buildSettings = {
290291
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
291292
INFOPLIST_FILE = PhotoCollectionDemo/Info.plist;
293+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
292294
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
293295
PRODUCT_BUNDLE_IDENTIFIER = luantran.PhotoCollectionDemo;
294296
PRODUCT_NAME = "$(TARGET_NAME)";

PhotoCollectionView/PhotoCollectionView.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,21 @@ open class PhotoCollectionView: UIView {
100100
label.text = "+\(numMore)"
101101

102102
photoView.addSubview(label)
103-
photoView.leftAnchor.constraint(equalTo: label.leftAnchor).isActive = true
104-
photoView.rightAnchor.constraint(equalTo: label.rightAnchor).isActive = true
105-
photoView.topAnchor.constraint(equalTo: label.topAnchor).isActive = true
106-
photoView.bottomAnchor.constraint(equalTo: label.bottomAnchor).isActive = true
103+
if #available(iOS 9.0, *) {
104+
photoView.leftAnchor.constraint(equalTo: label.leftAnchor).isActive = true
105+
photoView.rightAnchor.constraint(equalTo: label.rightAnchor).isActive = true
106+
photoView.topAnchor.constraint(equalTo: label.topAnchor).isActive = true
107+
photoView.bottomAnchor.constraint(equalTo: label.bottomAnchor).isActive = true
108+
109+
} else {
110+
let constraints = [
111+
NSLayoutConstraint(item: label, attribute: .left, relatedBy: .equal, toItem: photoView, attribute: .left, multiplier: 1.0, constant: 0),
112+
NSLayoutConstraint(item: label, attribute: .right, relatedBy: .equal, toItem: photoView, attribute: .right, multiplier: 1.0, constant: 0),
113+
NSLayoutConstraint(item: label, attribute: .top, relatedBy: .equal, toItem: photoView, attribute: .top, multiplier: 1.0, constant: 0),
114+
NSLayoutConstraint(item: label, attribute: .bottom, relatedBy: .equal, toItem: photoView, attribute: .bottom, multiplier: 1.0, constant: 0),
115+
]
116+
photoView.addConstraints(constraints)
117+
}
107118
}
108119
}
109120

PhotoCollectionView/PhotoView.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ class PhotoView: UIView {
2323
super.init(frame: frame)
2424

2525
addSubview(imageView)
26-
leftAnchor.constraint(equalTo: imageView.leftAnchor).isActive = true
27-
rightAnchor.constraint(equalTo: imageView.rightAnchor).isActive = true
28-
topAnchor.constraint(equalTo: imageView.topAnchor).isActive = true
29-
bottomAnchor.constraint(equalTo: imageView.bottomAnchor).isActive = true
26+
if #available(iOS 9.0, *) {
27+
leftAnchor.constraint(equalTo: imageView.leftAnchor).isActive = true
28+
rightAnchor.constraint(equalTo: imageView.rightAnchor).isActive = true
29+
topAnchor.constraint(equalTo: imageView.topAnchor).isActive = true
30+
bottomAnchor.constraint(equalTo: imageView.bottomAnchor).isActive = true
31+
} else {
32+
let constraints = [
33+
NSLayoutConstraint(item: imageView, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 0),
34+
NSLayoutConstraint(item: imageView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0),
35+
NSLayoutConstraint(item: imageView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0),
36+
NSLayoutConstraint(item: imageView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0),
37+
]
38+
addConstraints(constraints)
39+
}
3040

3141
backgroundColor = UIColor.black
3242
}

0 commit comments

Comments
 (0)