Use UIStackView directly in iOS6+

Related tags

UI FDStackView
Overview

FDStackView

Use UIStackView as if it supports iOS6. forkingdog

Problem

UIStackView is a very handy tool to build flow layout, but it's available only when iOS9+, we've found some great compatible replacements like OAStackView, but we want more:

  • Perfect downward compatible, no infectivity, use UIStackView directly as if it's shipped from iOS6.
  • Interface builder support, live preview.
  • Keep layout constraints as closely as UIStackView constructs.

Usage

Podfile

platform :ios, '7.0'
pod "FDStackView", "1.0"

Import nothing, learn nothing, it just works.

  • It will automatically replace the symbol for UIStackView into FDStackView at runtime before iOS9.
// Works in iOS6+, use it directly.
UIStackView *stackView = [[UIStackView alloc] init];
stackView.axis = UILayoutConstraintAxisHorizontal;
stackView.distribution = UIStackViewDistributionFill;
stackView.alignment = UIStackViewAlignmentTop;
[stackView addArrangedSubview:[[UILabel alloc] init]];
[self.view addSubview:stackView];
  • Interface Builder Support

Set Builds for option to iOS 9.0 and later to eliminate the version error in Xcode:

How to use in IB

Now, use UIStackView as you like and its reactive options and live preview:

UIStackView preview in IB

Requirements

  • Xcode 7+ (For interface builder supports and the latest Objective-C Syntax)
  • Base SDK iOS 9.0+ (To link UIStackView symbol in UIKit)

Versions

  • 1.0.1 is the lastest version. We released it after we have used it in our official application. And it was successfully passed through the App Store's review. So you have no concern to use it.

License

The MIT License (MIT)

Copyright (c) 2015-2016 forkingdog ( https://github.com/forkingdog )

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Crash in Demo proejct

    Crash in Demo proejct

    Use Storyboard mode, add view, remove view, add view then crash:

    2015-10-11 14:02:00.085 FDStackViewDemo[6976:177315] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Impossible to set up layout with view hierarchy unprepared for constraint.' *** First throw call stack: ( 0 CoreFoundation 0x0000000103216f35 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000102eb1bb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000103216d9a +[NSException raise:format:arguments:] + 106 3 Foundation 0x0000000102acf5df -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 UIKit 0x000000010412bcf2 __120-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]_block_invoke_2 + 177 5 UIKit 0x000000010412bbe7 -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 377 6 UIKit 0x000000010412bea4 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 30 7 UIKit 0x000000010412bfcc -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 243 8 FDStackViewDemo 0x0000000102967e66 -[FDStackViewDistributionLayoutArrangement resetFillEffect] + 1750 9 FDStackViewDemo 0x0000000102969979 -[FDStackViewDistributionLayoutArrangement resetAllConstraints] + 57 10 FDStackViewDemo 0x0000000102969ecb -[FDStackViewDistributionLayoutArrangement updateCanvasConnectionConstraintsIfNecessary] + 43 11 FDStackViewDemo 0x000000010296a57b -[FDStackViewLayoutArrangement updateArrangementConstraints] + 43 12 FDStackViewDemo 0x000000010296658a -[FDStackView updateLayoutArrangements] + 186 13 FDStackViewDemo 0x0000000102965bd5 -[FDStackView addArrangedSubview:] + 501 14 FDStackViewDemo 0x000000010296f40b -[FDStoryboardBasedViewController addAction:] + 779 15 UIKit 0x0000000103ab28be -[UIApplication sendAction:to:from:forEvent:] + 75 16 UIKit 0x0000000103bb9410 -[UIControl _sendActionsForEvents:withEvent:] + 467 17 UIKit 0x0000000103bb87df -[UIControl touchesEnded:withEvent:] + 522 18 UIKit 0x0000000103e5f540 _UIGestureRecognizerUpdate + 9487 19 UIKit 0x0000000103af7ff6 -[UIWindow _sendGesturesForEvent:] + 1041 20 UIKit 0x0000000103af8c23 -[UIWindow sendEvent:] + 667 21 UIKit 0x0000000103ac59b1 -[UIApplication sendEvent:] + 246 22 UIKit 0x0000000103ad2a7d _UIApplicationHandleEventFromQueueEvent + 17370 23 UIKit 0x0000000103aae103 _UIApplicationHandleEventQueue + 1961 24 CoreFoundation 0x000000010314c551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 25 CoreFoundation 0x000000010314241d __CFRunLoopDoSources0 + 269 26 CoreFoundation 0x0000000103141a54 __CFRunLoopRun + 868 27 CoreFoundation 0x0000000103141486 CFRunLoopRunSpecific + 470 28 GraphicsServices 0x00000001073959f0 GSEventRunModal + 161 29 UIKit 0x0000000103ab1420 UIApplicationMain + 1282 30 FDStackViewDemo 0x000000010296a7ff main + 111 31 libdyld.dylib 0x0000000105c3e145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

    opened by m1entus 5
  • iOS 8.3/8.4 phone5/5s/5c 卡顿严重,排渣找到了原因

    iOS 8.3/8.4 phone5/5s/5c 卡顿严重,排渣找到了原因

    • (void)intrinsicContentSizeInvalidatedForChildView:(UIView *)childView { [self.distributionArrangement intrinsicContentSizeInvalidatedForItem:childView]; [self.alignmentArrangement intrinsicContentSizeInvalidatedForItem:childView]; } 上面这个更新布局的方法,在iOS7 不会调用,iOS8 会疯狂的调用,会导致界面卡顿很严重,然后注释掉这段代码卡顿消失,界面也没用什么影响,想问下,这个方法的作用?
    opened by JasonXin 4
  • iOS 8 crash

    iOS 8 crash

    我在一个stackView中嵌套加了一个stackView, 嵌套的stackView动态添加imageView 在iOS8 crash, iOS9 正常。

    The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7f838fe60440 UIStackView:0x7f838fd331d0.leading == UIImageView:0x7f838fc30c10.leading>
        When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
    

    exception break point 定位在

    - (void)resetCanvasConnectionsEffect
    

    中的

    [self.canvas addConstraints:canvasConnectionConstraints];
    

    Uploading QQ20151028-1@2x.png…

    opened by sdaheng 4
  • Views do not respect 'Hidden' property in iOS 8 like they do in iOS9

    Views do not respect 'Hidden' property in iOS 8 like they do in iOS9

    One of the perks of UIStackView is that hidden views do not affect the layout. So if a view is marked as hidden it's as if it didn't exist. This behavior is absent from iOS8, where marking a view as hidden will still force it to occupy it's space.

    opened by toddrick 4
  •  在AutoLayout布局下的疑问

    在AutoLayout布局下的疑问

    CAlayer 层是不支持AutoLayout 一般用Frame 或者bounds 来计算大小 但是Autolayout布局确定的时机不对 如何读出正确的frame ViewController 有个 -viewDidLayoutSubviewS 方法

    那么问题来了 View怎么读?

    opened by ValiantCat 2
  • ios7 crash

    ios7 crash

    device: iPhone 4 iOS 7.1.2 step: add->remove->add

    Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint:<NSLayoutConstraint:0x16df7cb0 'FDSV-spacing' H:[UILabel:0x16df05c0]-(0)-[UILabel:0x16d52d40]> view:<UIStackView: 0x16ded770; frame = (0 0; 320 100); autoresize = RM+BM; layer = <FDTransformLayer: 0x16ded9b0>>'

    opened by zziking 2
  • 释放的时候kvo crash了。。。。iOS8.1模拟器

    释放的时候kvo crash了。。。。iOS8.1模拟器

    2015-10-09 18:14:45.803 Qingwen[74545:2004789] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <UIStackView 0x7fb183c8d350> for the key path "hidden" from <UIStackView 0x7fb183c99490> because it is not registered as an observer.' *** First throw call stack: ( 0 CoreFoundation 0x00000001074b7f35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000107124bb7 objc_exception_throw + 45 2 CoreFoundation 0x00000001074b7e6d +[NSException raise:format:] + 205 3 Foundation 0x0000000104375609 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 608 4 Foundation 0x000000010437530c -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 90 5 Qingwen 0x0000000102ec018b -[FDStackView removeHiddenObserverForView:] + 91 6 Qingwen 0x0000000102ebf8e5 -[FDStackView removeArrangedSubview:] + 421 7 Qingwen 0x0000000102ebf6fe -[FDStackView willRemoveSubview:] + 62 8 UIKit 0x000000010526649c __UIViewWillBeRemovedFromSuperview + 142 9 UIKit 0x00000001052661c9 -[UIView(Hierarchy) removeFromSuperview] + 91 10 UIKit 0x0000000105259e39 -[UIView dealloc] + 404 11 Qingwen 0x0000000102ec04af -[FDStackView dealloc] + 223 12 CoreFoundation 0x000000010738f78b CFRelease + 603 13 CoreFoundation 0x00000001073a30bd -[__NSArrayM dealloc] + 157 14 libobjc.A.dylib 0x000000010713928e _ZN11objc_object17sidetable_releaseEb + 236 15 libobjc.A.dylib 0x00000001071398cd _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 591 16 CoreFoundation 0x00000001073aeda6 _CFAutoreleasePoolPop + 22 17 CoreFoundation 0x00000001073e2ef3 __CFRunLoopRun + 2051 18 CoreFoundation 0x00000001073e2486 CFRunLoopRunSpecific + 470 19 GraphicsServices 0x000000010a31c9f0 GSEventRunModal + 161 20 UIKit 0x00000001051fb420 UIApplicationMain + 1282 21 Qingwen 0x0000000102ea4e0f main + 111 22 libdyld.dylib 0x00000001081ce145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

    opened by jl322137 1
  • 从StackView中删除添加的subView

    从StackView中删除添加的subView

    我在TableViewCell中使用StackView 重用时会出现重复添加view的问题,发现在addArrangedSubView 或 insertArrangedSubview:atIndex: 中 调用了 [self addSubview:view] 或 [self insertSubview:view atIndex:stackIndex] 但并没有在removeArrangedSubview: 中删除添加的view

    opened by sdaheng 0
  • 真机上不起作用,模拟器上起作用。

    真机上不起作用,模拟器上起作用。

    使用步骤: 1、项目中导入了FDStackView; 2、然后在一个xib文件中添加了一个StackView (已经正确添加约束) 3、在步骤2中创建的StackView中添加4个按钮,StackView的相关属性设置为: Axis: Horizontal Alignment: Center Distribution: Equal Spacing Spacing: 0

    结果: 在iPhone6 iOS8.2 和 iPhone5 iOS9.1 真机上只显示前三个按钮。 在对应的模拟器上正常。 请问是我哪里设置错误了吗?

    opened by JianrongHui 0
  • iOS11新增功能提供

    iOS11新增功能提供

    系统新增了下面几个Api有没有计划提供

    • (void)setCustomSpacing:(CGFloat)spacing afterView:(UIView *)arrangedSubview API_AVAILABLE(ios(11.0),tvos(11.0));
    • (CGFloat)customSpacingAfterView:(UIView *)arrangedSubview API_AVAILABLE(ios(11.0),tvos(11.0));
    opened by dev-zlcode 1
  • addArrangedSubview逻辑错误

    addArrangedSubview逻辑错误

    stackView依次有4个arrangedSubview:view1red,view2yellow,view3green,view4orange

    在系统方法中再次调用[stackView addArrangedSubview:view2yellow];view2yellow会被移动到最后面,view顺序变成view1red,view3green,view4orange,view2yellow

    但是在iOS8 FDStackView中view2yellow的位置不会变动。

    opened by Whichcolor 0
  • 在iOS10上removeAllSubviews后,再调用addArrangedSubview Crash

    在iOS10上removeAllSubviews后,再调用addArrangedSubview Crash

    在iOS10上removeAllSubviews后,再调用addArrangedSubview Crash,什么原因?

    报错: Assertion failure in -[FDStackView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.7.47/NSLayoutConstraint_UIKitAdditions.m:649 invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.

    opened by luowei 0
Owner
Staying like a fool, forking like a dog.
null
A micro UIStackView convenience API inspired by SwiftUI

Stacks A micro UIStackView convenience API inspired by SwiftUI. let stack: UIView = .hStack(alignment: .center, margins: .all(16), [ .vStack(spaci

Alexander Grebenyuk 74 Jul 27, 2022
Porting UIStackView to iOS 7+

OAStackView iOS 9 introduced the very cool UIStackView, UIStackView can be used to easily create simple and complex layouts. As expected UIStackView c

Omar Abdelhafith 2.2k Dec 3, 2022
An alternative to UIStackView for common Auto Layout patterns.

StackLayout StackLayout builds on Auto Layout to make some of the most common layouts easier to manage. It creates the constraints that you need and a

Bridger Maxwell 76 Jun 29, 2022
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Mukesh Thawani 467 Dec 5, 2022
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 1, 2023
An easy to use UI component to help display a signal bar with an added customizable fill animation

TZSignalStrengthView for iOS Introduction TZSignalStrengthView is an easy to use UI component to help display a signal bar with an added customizable

TrianglZ LLC 22 May 14, 2022
Easy-to-use HStack that snaps to elements on scroll.

SnapToScroll Drop-in SwiftUI-based container view for horizontal snapping. example-video.mp4 Getting Started Using SnapToScroll is straightforward. Th

null 206 Jan 7, 2023
Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements

SwiftUIKitView Easily use UIKit views in SwiftUI. Convert UIView to SwiftUI View Create Xcode Previews from UIView elements SwiftUI functional updatin

Antoine van der Lee 682 Dec 29, 2022
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Mukesh Thawani 466 Nov 9, 2021
Use the iPhone X notch in creative ways 👩‍🎨👨‍🎨.

NotchToolkit NotchToolkit is a framework for iOS that allow developers use the iPhone X notch space in creative ways. Inspired by I was working on thi

Ahmed Bekhit 56 Nov 22, 2022
Easy to use, highly customizable gauge view

GDGauge - Customizable Gauge View Requirements Xcode 11+ Swift 5 iOS 9+ Installation Swift Package Manager .package(url: "https://github.com/saeid/GDG

Saeid 74 Dec 5, 2022
UIStackView replica for iOS 7.x and iOS 8.x

TZStackView A wonderful layout component called the UIStackView was introduced with iOS 9. With this component it is really easy to layout components

Tom van Zummeren 1.2k Oct 10, 2022
A micro UIStackView convenience API inspired by SwiftUI

Stacks A micro UIStackView convenience API inspired by SwiftUI. let stack: UIView = .hStack(alignment: .center, margins: .all(16), [ .vStack(spaci

Alexander Grebenyuk 74 Jul 27, 2022
UICollectionView and UIStackView Homework

UICollectionView and UIStackView Homework Use one outer StackView containing one CollectionView on top and a horizontal StackView at the bottom with t

null 0 Nov 11, 2021
Porting UIStackView to iOS 7+

OAStackView iOS 9 introduced the very cool UIStackView, UIStackView can be used to easily create simple and complex layouts. As expected UIStackView c

Omar Abdelhafith 2.2k Dec 3, 2022
An alternative to UIStackView for common Auto Layout patterns.

StackLayout StackLayout builds on Auto Layout to make some of the most common layouts easier to manage. It creates the constraints that you need and a

Bridger Maxwell 76 Jun 29, 2022
CalendarApp Swift - Made a calendar app in swift, completely from scratch using UIStackView and UICollectionView

CalendarApp_Swift Made a calendar app in swift, completely from scratch using UI

Arnav Chhokra 1 Feb 4, 2022
A data-driven UIScrollView + UIStackView framework for building fast and flexible lists

JKListKit A data-driven UIScrollView + UIStackView framework for building fast and flexible lists. Full Oficial documentation Main Features ?? Create

Juan Vasquez 2 Mar 15, 2022
Localize your views directly in Interface Builder with IBLocalizable

Localize your views easily in Interface Builder with IBLocalizable. With IBLocalizable, you can localize your views in Interface Builder easily. Simpl

Chris Jimenez 461 Dec 29, 2022
Super lightweight library that helps you to localize strings, even directly in storyboards!

Translatio Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 9 or higher. Swi

Andrea Mario Lufino 19 Jan 29, 2022