Skip to content

Commit

Permalink
Fixed centering view
Browse files Browse the repository at this point in the history
  • Loading branch information
pchelnikov committed Aug 11, 2018
1 parent d46e6cd commit f52b298
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion MarkerKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Lightweight and easy to use wrapper for Auto Layout Constraints (iOS 8+ support), inspired by [https://github.com/ustwo/autolayout-helper-swift](https://github.com/ustwo/autolayout-helper-swift)

[![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/pchelnikov/MarkerKit/blob/master/LICENSE)
[![Platform](https://img.shields.io/cocoapods/p/MarkerKit.svg?style=flat)](https://github.com/SnapKit/SnapKit)
[![Platform](https://img.shields.io/cocoapods/p/MarkerKit.svg?style=flat)](https://github.com/pchelnikov/MarkerKit)
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/MarkerKit.svg)](https://cocoapods.org/pods/MarkerKit)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

Expand Down Expand Up @@ -147,8 +147,9 @@ UIView.animate(withDuration: 0.3) {
```

## What to do next

* Writing tests

## License

Device is available under the MIT license. See the LICENSE file for more info.
MarkerKit is available under the MIT license. See the LICENSE file for more info.
13 changes: 4 additions & 9 deletions Sources/MarkerKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,10 @@ public struct MarkerConstraintView {

@discardableResult
public func center(to view: Any?) -> [NSLayoutConstraint] {
var constraints: [NSLayoutConstraint] = []

if let superview = self.view.superview {
let centerXConstraint = centerX(to: superview)
let centerYConstraint = centerY(to: superview)

constraints = [centerXConstraint, centerYConstraint]
}

let centerXConstraint = centerX(to: view)
let centerYConstraint = centerY(to: view)
let constraints = [centerXConstraint, centerYConstraint]

return constraints
}

Expand Down
26 changes: 0 additions & 26 deletions iOS-Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

window = UIWindow(frame: UIScreen.main.bounds)
Expand All @@ -25,29 +24,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

16 changes: 14 additions & 2 deletions iOS-Example/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,7 +20,19 @@
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="MarkerKit Example" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dGr-Qj-r7X">
<rect key="frame" x="85" y="319" width="205" height="29"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="dGr-Qj-r7X" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="Ahi-uj-fbm"/>
<constraint firstItem="dGr-Qj-r7X" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="KO9-Vf-GJl"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 1 addition & 1 deletion iOS-Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
7 changes: 7 additions & 0 deletions iOS-Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ViewController: UIViewController {
private let leftTopView = UIView()
private let rightBottomView = UIView()
private let centerView = UIView()
private let subCenterView = UIView()
private let secondCenterView = UIView()

override func viewDidLoad() {
Expand All @@ -28,11 +29,13 @@ class ViewController: UIViewController {
leftTopView.backgroundColor = UIColor.blue.withAlphaComponent(0.5)
rightBottomView.backgroundColor = UIColor.green.withAlphaComponent(0.5)
centerView.backgroundColor = UIColor.red.withAlphaComponent(0.5)
subCenterView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
secondCenterView.backgroundColor = UIColor.yellow.withAlphaComponent(0.5)

view.addSubview(leftTopView)
view.addSubview(rightBottomView)
view.addSubview(centerView)
view.addSubview(subCenterView)
view.addSubview(secondCenterView)
}

Expand All @@ -55,5 +58,9 @@ class ViewController: UIViewController {
secondCenterView.mrk.leading(to: centerView, attribute: .centerX, relation: .equal, constant: 0)
secondCenterView.mrk.width(100)
secondCenterView.mrk.height(70)

subCenterView.mrk.center(to: secondCenterView)
subCenterView.mrk.width(30)
subCenterView.mrk.height(30)
}
}

0 comments on commit f52b298

Please sign in to comment.