{"id":17078665,"url":"https://github.com/marty-suzuki/misterfusion","last_synced_at":"2025-04-07T06:11:59.918Z","repository":{"id":62447839,"uuid":"46105844","full_name":"marty-suzuki/MisterFusion","owner":"marty-suzuki","description":"MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class.","archived":false,"fork":false,"pushed_at":"2019-09-30T16:55:35.000Z","size":4846,"stargazers_count":314,"open_issues_count":0,"forks_count":26,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-04-30T23:13:25.806Z","etag":null,"topics":["autolayout","carthage","cocoapods","ios","iphone-x","macos","safe-area","swift","tvos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marty-suzuki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-13T07:06:54.000Z","updated_at":"2024-04-27T13:30:22.000Z","dependencies_parsed_at":"2022-11-01T23:17:39.266Z","dependency_job_id":null,"html_url":"https://github.com/marty-suzuki/MisterFusion","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FMisterFusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FMisterFusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FMisterFusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FMisterFusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marty-suzuki","download_url":"https://codeload.github.com/marty-suzuki/MisterFusion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601448,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autolayout","carthage","cocoapods","ios","iphone-x","macos","safe-area","swift","tvos"],"created_at":"2024-10-14T12:23:00.932Z","updated_at":"2025-04-07T06:11:59.883Z","avatar_url":"https://github.com/marty-suzuki.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MisterFusion\n\n[![Platform](http://img.shields.io/badge/platform-iOS%20|%20tvOS%20|%20macOS-blue.svg?style=flat\n)](https://developer.apple.com/iphone/index.action)\n[![Language](http://img.shields.io/badge/swift-5-orange.svg?style=flat\n)](https://developer.apple.com/swift)\n[![Version](https://img.shields.io/cocoapods/v/MisterFusion.svg?style=flat)](http://cocoapods.org/pods/MisterFusion)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/MisterFusion.svg?style=flat)](http://cocoapods.org/pods/MisterFusion)\n[![Build Status](https://travis-ci.org/marty-suzuki/MisterFusion.svg?branch=master)](https://travis-ci.org/marty-suzuki/MisterFusion)\n\n![](./Images/logo.png)\n\nMisterFusion makes more easier to use AutoLayout in Swift \u0026 Objective-C code.\n\n## Features\n- [x] Simple And Concise Syntax\n- [x] Use in Swift and Objective-C\n- [x] Support Size Class\n- [x] Support Swift5\n- [x] Support Swift4 (until 4.0.1)\n- [x] Support SafeArea🎉 (Swift3.2 since 2.3.1, Swift4 since 3.1.0)\n- [x] Support iOS\n- [x] Support tvOS (since 3.2.0)\n- [x] Support macOS (since 4.0.0)\n\n#### MisterFusion Code for Swift\n\n```swift\nlet view = UIView()\nself.view.mf.addSubview(view, andConstraints:\n    view.top    |+| 10,\n    view.right  |-| 10,\n    view.left   |+| 10,\n    view.bottom |-| 10\n)\n```\n\n#### Ordinary Code for Swift\n\nThis is same implementation as above code, but this is hard to see.\n\n```swift\nlet view = UIView()\nself.view.addSubview(view)\nview.translatesAutoresizingMaskIntoConstraints = false\nself.view.addConstraints([\n    NSLayoutConstraint(item: view, attribute: .top,    relatedBy: .equal, toItem: self.view, attribute: .top,    multiplier: 1, constant:  10),\n    NSLayoutConstraint(item: view, attribute: .right,  relatedBy: .equal, toItem: self.view, attribute: .right,  multiplier: 1, constant: -10),\n    NSLayoutConstraint(item: view, attribute: .left,   relatedBy: .equal, toItem: self.view, attribute: .left,   multiplier: 1, constant:  10),\n    NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1, constant: -10),\n])\n```\n\n#### MisterFusion Code for Objective-C\n\n```objective-c\nUIView *view = [UIView new];\n[self.view addLayoutSubview:view andConstraints:@[\n    view.Top   .Constant(10.0f),\n    view.Right .Constant(-10.0f),\n    view.Left  .Constant(10.0f),\n    view.Bottom.Constant(-10.0f)\n]];\n```\n\n#### Ordinary Code for Objective-C\n\nThis is same implementation as above code, but this is hard to see.\n\n```objective-c\nUIView *view = [UIView new];\nview.translatesAutoresizingMaskIntoConstraints = NO;\n[self.view addSubview: view];\n[self.view addConstraints:@[\n    [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop    relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop    multiplier:1.0f constant:10.0f],\n    [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeRight  relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight  multiplier:1.0f constant:-10.0f],\n    [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft   relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft   multiplier:1.0f constant:10.0f],\n    [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:0.5f constant:-15.0f]\n]];\n```\n\n#### Sample Layout\n\n![](./Images/layout.png)\n\nIf you want to realize layout like a above image, needed code is only this.\n\n```swift\nlet redView = UIView()\nredView.backgroundColor = .red\nself.view.mf.addSubview(redView, andConstraints:\n    redView.top   |+| 10,\n    redView.right |-| 10,\n    redView.left  |+| 10\n)\n\nlet yellowView = UIView()\nyellowView.backgroundColor = .yellow\nself.view.mf.addSubview(yellowView, andConstraints:\n    yellowView.top    |==| redView.bottom |+| 10,\n    yellowView.left   |+|  10,\n    yellowView.bottom |-|  10,\n    yellowView.height |==| redView.height\n)\n\nlet greenView = UIView()\ngreenView.backgroundColor = .green\nself.view.mf.addSubview(greenView, andConstraints:\n    greenView.top    |==| redView.bottom    |+| 10,\n    greenView.left   |==| yellowView.right  |+| 10,\n    greenView.bottom |-|  10,\n    greenView.right  |-|  10,\n    greenView.width  |==| yellowView.width,\n    greenView.height |==| yellowView.height\n)\n```\n\n## Installation\n\n#### CocoaPods\n\nMisterFusion is available through [CocoaPods](http://cocoapods.org). If you have cocoapods 0.39.0 or greater, you can install\nit, simply add the following line to your Podfile:\n\n\tpod 'MisterFusion'\n\nIn addtion, import **MisterFusion** like this.\n\n##### Swift\n\n    import MisterFusion\n\n##### Objective-C\n\n    #import \u003cMisterFusion/MisterFusion-Swift.h\u003e\n\n#### Carthage\n\nIf you’re using [Carthage](https://github.com/Carthage/Carthage), simply add\nMisterFusion to your `Cartfile`:\n\n```\ngithub \"szk-atmosphere/MisterFusion\"\n```\nMake sure to add `MisterFusion.framework` to \"Linked Frameworks and Libraries\" and \"copy-frameworks\" Build Phases.\n\n## Advanced Setting\n\nYou can set `multiplier`, `constant` and `priority` like this.\n(This is same implementation as [first example](#misterfusion-code-for-swift).)\n\n#### Swift\n\n```swift\nself.view.mf.addSubview(view, andConstraints:\n    view.top    |==| self.view.top    |*| 1 |+| 10 |\u003c\u003e| UILayoutPriorityRequired,\n    view.right  |==| self.view.right  |*| 1 |-| 10 |\u003c\u003e| UILayoutPriorityRequired,\n    view.left   |==| self.view.left   |*| 1 |+| 10 |\u003c\u003e| UILayoutPriorityRequired,\n    view.bottom |==| self.view.bottom |*| 1 |-| 10 |\u003c\u003e| UILayoutPriorityRequired\n)\n```\n\n#### Objective-C\n\n```objective-c\n[self.view addLayoutSubview:view andConstraints:@[\n    view.Top   .Equal(self.view.Top)   .Multiplier(1.0f).Constant(10.0f) .Priority(UILayoutPriorityRequired),\n    view.Right .Equal(self.view.Right) .Multiplier(1.0f).Constant(-10.0f).Priority(UILayoutPriorityRequired),\n    view.Left  .Equal(self.view.Left)  .Multiplier(1.0f).Constant(10.0f) .Priority(UILayoutPriorityRequired),\n    view.Bottom.Equal(self.view.Bottom).Multiplier(1.0f).Constant(-10.0f).Priority(UILayoutPriorityRequired)\n]];\n```\n\n## For Swift\n\n#### Operators\n\n- `|==|`, `|\u003c=|`, `|\u003e=|` ... `NSLayoutRelation` and fixed `height` and `width`\n- `|*|`, `|/|` ... `multiplier`\n- `|+|`, `|-|` ... `constant`\n- `|\u003c\u003e|` ... `UILayoutPriority`\n- `\u003c|\u003e` ... `UIUserInterfaceSizeClass` for VerticalSizeClass\n- `\u003c-\u003e` ... `UIUserInterfaceSizeClass` for HorizontalSizeClass\n- `-=-` ... Identifier\n\n#### UIView Extensions\n\n```swift\npublic func addLayoutConstraint(_ misterFusion: MisterFusion) -\u003e NSLayoutConstraint?\npublic func addLayoutConstraints(_ misterFusions: MisterFusion...) -\u003e [NSLayoutConstraint]\npublic func addLayoutConstraints(_ misterFusions: [MisterFusion]) -\u003e [NSLayoutConstraint]\npublic func addLayoutSubview(_ subview: UIView, andConstraint misterFusion: MisterFusion) -\u003e NSLayoutConstraint?\npublic func addLayoutSubview(_ subview: UIView, andConstraints misterFusions: [MisterFusion]) -\u003e [NSLayoutConstraint]\npublic func addLayoutSubview(_ subview: UIView, andConstraints misterFusions: MisterFusion...) -\u003e [NSLayoutConstraint]\npublic func insertLayoutSubview(_ subview: UIView, at index: Int, andConstraint misterFusion: MisterFusion) -\u003e NSLayoutConstraint?\npublic func insertLayoutSubview(_ subview: UIView, at index: Int, andConstraints misterFusions: [MisterFusion]) -\u003e [NSLayoutConstraint]\npublic func insertLayoutSubview(_ subview: UIView, at index: Int, andConstraints misterFusions: MisterFusion...) -\u003e [NSLayoutConstraint]\npublic func insertLayoutSubview(_ subview: UIView, belowSubview siblingSubview: UIView, andConstraint misterFusion: MisterFusion) -\u003e NSLayoutConstraint?\npublic func insertLayoutSubview(_ subview: UIView, belowSubview siblingSubview: UIView, andConstraints misterFusions: [MisterFusion]) -\u003e [NSLayoutConstraint]\npublic func insertLayoutSubview(_ subview: UIView, belowSubview siblingSubview: UIView, andConstraints misterFusions: MisterFusion...) -\u003e [NSLayoutConstraint]\npublic func insertLayoutSubview(_ subview: UIView, aboveSubview siblingSubview: UIView, andConstraint misterFusion: MisterFusion) -\u003e NSLayoutConstraint?\npublic func insertLayoutSubview(_ subview: UIView, aboveSubview siblingSubview: UIView, andConstraints misterFusions: [MisterFusion]) -\u003e [NSLayoutConstraint]\npublic func insertLayoutSubview(_ subview: UIView, aboveSubview siblingSubview: UIView, andConstraints misterFusions: MisterFusion...) -\u003e [NSLayoutConstraint]\n```\n\n#### Array Extensions\n\n```swift\npublic func firstItem(_ view: UIView) -\u003e [NSLayoutConstraint]    \npublic func firstAttribute(_ attribute: NSLayoutAttribute) -\u003e [NSLayoutConstraint]   \npublic func relation(_ relation: NSLayoutRelation) -\u003e [NSLayoutConstraint]  \npublic func secondItem(_ view: UIView) -\u003e [NSLayoutConstraint]    \npublic func secondAttribute(_ attribute: NSLayoutAttribute) -\u003e [NSLayoutConstraint]\n```\n\nYou can get added `NSLayoutConstraint` with those functions.\nThis is a example.\n\n```swift\nlet bottomConstraint: NSLayoutConstraint = self.view.addLayoutSubview(view, andConstraints:\n    view.top    |+| 10,\n    view.right  |-| 10,\n    view.left   |+| 10,\n    view.bottom |-| 10\n).firstAttribute(.bottom).first\n```\n\nYou can use `Size Class` with `func traitCollectionDidChange(previousTraitCollection: UITraitCollection?)`.\n\n![](./Images/misterfusion.gif)\n\nThis is an example Regular, Compact size for iPhone6s+.\n\n```swift\noverride func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {\n    guard let whiteView = whiteView, redView = redView else { return }\n    if let whiteViewHeightConstraint = whiteViewWidthConstraint {\n        redView.removeConstraint(whiteViewHeightConstraint)\n    }\n    self.whiteViewWidthConstraint = redView.mf.addConstraints(\n        whiteView.width |-| 20 \u003c|\u003e .compact \u003c-\u003e .regular,\n        whiteView.width |*| 0.5 |-| 10 \u003c|\u003e .regular \u003c-\u003e .compact\n    ).firstAttribute(.width).first\n}\n```\n\n* A detail sample is [here](./Example/MisterFusionSample/ViewController.swift)\n\n#### Safe Area\n\nYou can use `view.safeArea.top` and so on. This is supported Safe Area.\n\n```swift\nview.mf.addConstraints(\n    yellowView.top    |==| redView.bottom       |+| 10,\n    yellowView.right  |==| view.safeArea.right  |-| 10,\n    yellowView.left   |==| view.safeArea.left   |+| 10,\n    yellowView.height |==| view.safeArea.height |/| 2 |-| 15\n)\n```\nIf OS version is below iOS 11, `view.safeArea.top` returns `view.top` internally.\n\n![](./Images/iphone_x.gif)\n\nThose are accessible safeArea properties.\n\n```swift\nextension UIView {\n    public var safeArea: UIViewSafeArea { get }\n}\n\nextension UIViewSafeArea {\n    public var top: MisterFusion { get }\n    public var right: MisterFusion { get }\n    public var left: MisterFusion { get }\n    public var bottom: MisterFusion { get }\n    public var height: MisterFusion { get }\n    public var width: MisterFusion { get }\n    public var leading: MisterFusion { get }\n    public var trailing: MisterFusion { get }\n    public var centerX: MisterFusion { get }\n    public var centerY: MisterFusion { get }\n    public var notAnAttribute: MisterFusion { get }\n    public var lastBaseline: MisterFusion { get }\n    public var firstBaseline: MisterFusion { get }\n    public var leftMargin: MisterFusion { get }\n    public var rightMargin: MisterFusion { get }\n    public var topMargin: MisterFusion { get }\n    public var bottomMargin: MisterFusion { get }\n    public var leadingMargin: MisterFusion { get }\n    public var trailingMargin: MisterFusion { get }\n    public var centerXWithinMargins: MisterFusion { get }\n    public var centerYWithinMargins: MisterFusion { get }\n}\n```\n\nIn ViewController, you can use `self.safeArea.top` and `self.safeArea.bottom`.\n\nGreater than or equal to iOS 11, `self.safeArea.top` returns `self.view.safeAreaLayoutGuide.topAnchor`.\nAnd `self.safeArea.bottom` returns, `self.view.safeAreaLayoutGuide.bottomAnchor`.\n\nLess then or equal to iOS 10, `self.safeArea.top` returns 'self.topLayoutGuide.bottomAnchor'.\nAnd `self.safeArea.bottom` returns, `self.bottomLayoutGuide.topAnchor`.\n\n```swift\nextension UIViewController {\n    public var safeArea: UIViewControllerSafeArea { get }\n}\n\nextension UIViewControllerSafeArea {\n    public var top: MisterFusion { get }\n    public var bottom: MisterFusion { get }\n}\n```\n\n## For Objective-C\n\n### Readonly Blocks\n\n```objective-c\n@interface MisterFusion : NSObject\n//NSLayoutRelation\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull Equal)(MisterFusion * __nonnull);\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull LessThanOrEqual)(MisterFusion * __nonnull);\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull GreaterThanOrEqual)(MisterFusion * __nonnull);\n//multiplier\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull Multiplier)(CGFloat);\n//constant\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull Constant)(CGFloat);\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull NotRelatedEqualConstant)(CGFloat);\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull NotRelatedLessThanOrEqualConstant)(CGFloat);\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull NotRelatedGreaterThanOrEqualConstant)(CGFloat);\n//@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull NotRelatedConstant)(CGFloat); (deprecated since 1.1.0, use NotRelatedEqualConstant)\n//UILayoutPriority\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull Priority)(UILayoutPriority);\n//UIUserInterfaceSizeClass for HorizontalSizeClass\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull HorizontalSizeClass)(UIUserInterfaceSizeClass);\n//UIUserInterfaceSizeClass for VerticalSizeClass\n@property (nonatomic, readonly, copy) MisterFusion * __nullable (^ __nonnull VerticalSizeClass)(UIUserInterfaceSizeClass);\n//Identifier\n@property (nonatomic, readonly, copy) MisterFusion * _Nullable (^ _Nonnull Identifier)(NSString * _Nonnull);\n@end\n```\n\n#### UIView Category\n\n```objective-c\n- (NSLayoutConstraint * _Nullable)addLayoutConstraint:(MisterFusion * _Nonnull)misterFusion;\n- (NSArray\u003cNSLayoutConstraint *\u003e * _Nonnull)addLayoutConstraints:(NSArray\u003cMisterFusion *\u003e * _Nonnull)misterFusions;\n- (NSLayoutConstraint * _Nullable)addLayoutSubview:(UIView * _Nonnull)subview andConstraint:(MisterFusion * _Nonnull)misterFusion;\n- (NSArray\u003cNSLayoutConstraint *\u003e * _Nonnull)addLayoutSubview:(UIView * _Nonnull)subview andConstraints:(NSArray\u003cMisterFusion *\u003e * _Nonnull)misterFusions;\n- (NSLayoutConstraint * _Nullable)insertLayoutSubview:(UIView * _Nonnull)subview atIndex:(NSInteger)index andConstraint:(MisterFusion * _Nonnull)misterFusion;\n- (NSArray\u003cNSLayoutConstraint *\u003e * _Nonnull)insertLayoutSubview:(UIView * _Nonnull)subview atIndex:(NSInteger)index andConstraints:(NSArray\u003cMisterFusion *\u003e * _Nonnull)misterFusions;\n- (NSLayoutConstraint * _Nullable)insertLayoutSubview:(UIView * _Nonnull)subview belowSubview:(UIView * _Nonnull)siblingSubview andConstraint:(MisterFusion * _Nonnull)misterFusion;\n- (NSArray\u003cNSLayoutConstraint *\u003e * _Nonnull)insertLayoutSubview:(UIView * _Nonnull)subview belowSubview:(UIView * _Nonnull)siblingSubview andConstraints:(NSArray\u003cMisterFusion *\u003e * _Nonnull)misterFusions;\n- (NSLayoutConstraint * _Nullable)insertLayoutSubview:(UIView * _Nonnull)subview aboveSubview:(UIView * _Nonnull)siblingSubview andConstraint:(MisterFusion * _Nonnull)misterFusion;\n- (NSArray\u003cNSLayoutConstraint *\u003e * _Nonnull)insertLayoutSubview:(UIView * _Nonnull)subview aboveSubview:(UIView * _Nonnull)siblingSubview andConstraints:(NSArray\u003cMisterFusion *\u003e * _Nonnull)misterFusions;\n```\n\n#### NSArray Category\n```objective-c\n@property (nonatomic, readonly, copy) NSArray * __nonnull (^ __nonnull FirstItem)(UIView * __nonnull);\n@property (nonatomic, readonly, copy) NSArray * __nonnull (^ __nonnull FirstAttribute)(NSLayoutAttribute);\n@property (nonatomic, readonly, copy) NSArray * __nonnull (^ __nonnull SecondItem)(UIView * __nonnull);\n@property (nonatomic, readonly, copy) NSArray * __nonnull (^ __nonnull SecondAttribute)(NSLayoutAttribute);\n@property (nonatomic, readonly, copy) NSArray * __nonnull (^ __nonnull Reration)(NSLayoutRelation);\n```\n\nYou can get added `NSLayoutConstraint` with those properties.\nThis is a example.\n\n```objective-c\nNSLayoutConstraint *bottomConstraint = [self.view addLayoutSubview:view andConstraints:@[\n    view.Top   .Constant(10.0f),\n    view.Right .Constant(-10.0f),\n    view.Left  .Constant(10.0f),\n    view.Bottom.Constant(-10.0f)\n]].FirstAttribute(NSLayoutAttributeBottom).firstObject;\n```\n\nYou can use `Size Class` with `- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection`.\n\n![](./Images/misterfusion.gif)\n\nThis is an example Regular, Compact size for iPhone6s+.\n\n```objective-c\n- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {\n    [self.redView removeConstraint:self.whiteViewWidthConstraint];\n    self.whiteViewWidthConstraint = [self.redView addLayoutConstraints:@[\n        self.whiteView.Width.Multiplier(0.5f).Constant(-10).VerticalSizeClass(UIUserInterfaceSizeClassRegular).HorizontalSizeClass(UIUserInterfaceSizeClassCompact),\n        self.whiteView.Width.Constant(-20).VerticalSizeClass(UIUserInterfaceSizeClassCompact).HorizontalSizeClass(UIUserInterfaceSizeClassRegular)\n    ]].FirstAttribute(NSLayoutAttributeWidth).firstObject;\n}\n```\n\n* A detail sample is [here](./Example/MisterFusionSample/MFViewController.m)\n\n#### Safe Area\n\nYou can use `self.view.SafeAreaTop` and so on. This is supported Safe Area.\n\n```objective-c\n[self.view addLayoutConstraints:@[\n    yellowView.Top   .Equal(redView.Bottom)          .Constant(10.0f),\n    yellowView.Right .Equal(self.view.SafeAreaRight) .Constant(-10.0f),\n    yellowView.Left  .Equal(self.view.SafeAreaLeft)  .Constant(10.0f),\n    yellowView.Height.Equal(self.view.SafeAreaHeight).Multiplier(0.5f).Constant(-15.0f)\n]];\n```\n\nIf OS version is below iOS 11, `self.view.SafeAreaTop` returns `self.view.Top` internally.\n\n![](./Images/iphone_x.gif)\n\nThose are accessible safeArea properties.\n\n```objective-c\n// UIView\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaTop;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaRight;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaLeft;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaBottom;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaHeight;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaWidth;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaLeading;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaTrailing;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaCenterX;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaCenterY;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaNotAnAttribute;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaLastBaseline;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaFirstBaseline;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaLeftMargin;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaRightMargin;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaTopMargin;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaBottomMargin;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaLeadingMargin;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaTrailingMargin;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaCenterXWithinMargins;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaCenterYWithinMargins;\n```\n\nIn ViewController, you can use `self.SafeAreaTop` and `self.SafeAreaBottom`.\n\nGreater than or equal to iOS 11, `self.SafeAreaTop` returns `self.view.safeAreaLayoutGuide.topAnchor`.\nAnd `self.SafeAreaBottom` returns, `self.view.safeAreaLayoutGuide.bottomAnchor`.\n\nLess then or equal to iOS 10, `self.SafeAreaTop` returns 'self.topLayoutGuide.bottomAnchor'.\nAnd `self.SafeAreaBottom` returns, `self.bottomLayoutGuide.topAnchor`.\n\n```objective-c\n// UIViewController\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaTop;\n@property (nonatomic, readonly, strong) MisterFusion * _Nonnull SafeAreaBottom;\n```\n\n## Requirements\n\n- Xcode 10.2 or greater\n- iOS 8.0 or greater\n- tvOS 10.0 or greater\n- macOS 10.11 or greater\n\n## Author\n\nTaiki Suzuki, s1180183@gmail.com\n\n## License\n\nMisterFusion is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty-suzuki%2Fmisterfusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarty-suzuki%2Fmisterfusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty-suzuki%2Fmisterfusion/lists"}