Coder Social home page Coder Social logo

tzstackview's Introduction

TZStackView

Build status

This is a port of Tom van Zummeren's TZStackView, which provides a backport of UIStackView, which was introduced in iOS 9.

StackView provides an easy way to lay out views horizontally and vertically and UIStackView is the new recommended way to lay out things in iOS 9, instead of resolving to use explicit view constraints.

Features

  • Compatible with iOS 7 and 8

  • Complete API of UIStackView with all distribution and alignment options

  • Animation of hidden property

  • Support for storyboards.

Installing

Add the TZStackView nuget to your Xamarin.iOS project

Install-Package TZStackView

Usage

Given view1, view2 and view3 have intrinsic content sizes set to 100x100, 80x80 and 60x60 respectively.

var stackView = new StackView(new UIView[] {view1, view2, view3})
{
    Axis = UILayoutConstraintAxis.Vertical,
    Distribution = Distribution.FillEqually,
    Alignment = Alignment.Center,
    Spacing = 25
};

This will produce the following layout. Layout Example

To animate adding or removing a view from the arranged subviews simply toggle the Hidden property on the view.

UIView.AnimateNotify(0.6, 0, 0.7f, 0, UIViewAnimationOptions.AllowUserInteraction, 
	() => { view.Hidden = true; }, completed => { });

Migrating to UIStackView

If you at some point want to make iOS 9 the minimum target of your application, you will want to replace this with UIStackView. Since TZStackView is a drop in replacement of UIStackView, you should be able to just use UIStackView instead.

var stackView = StackView(subViews);
var stackView = UIStackView(subViews);

License

TZStackView is licensed under the MIT License. See the LICENSE file for details.

tzstackview's People

Contributors

cheesebaron avatar dependabot-preview[bot] avatar

Stargazers

Yauheni Pakala avatar Jonah avatar Robert Strand avatar nmilcoff avatar Will Sahatdjian avatar Martijn van Dijk avatar Solli Moreira Honorio avatar Jens Becker avatar Aktar avatar Lukáš Vavrek avatar ZeBen avatar Jean-Marie Alfonsi avatar Erlend Angelsen avatar

Watchers

 avatar Aktar avatar James Cloos avatar Lukáš Vavrek avatar

tzstackview's Issues

FillProportionally Distribution not working as expected

As the title says, the FillProportionally distribution seems to have a bug.

I didn't find the problem yet, but it is really easy to reproduce:

Reproduction sample: Sample hosted in repo.
Use case: Run the sample -> Tap Horizontal option in segmented control -> Tap FillProportionally option.
Expected behaviour: Since all views have intrinsic content size set, all of them should be visible.
Actual behaviour: Only one view is displayed.

simulator screen shot 26 mar 2017 12 32 23

TZStackView Storyboard Support does not seem to be working

TZStackView is supposed to support Storyboards (says so in ReadMe), but the vertical StackView is not laying out properly. One thing I noticed is that in the Xamarin design view I get an "Error while creating this entry" screen shot below.

Also I'm attaching my Xamarin project (see Junk.zip), where u'll see that the StackView setup in ViewController.cs is totally ignored:
StackView.Distribution = TZStackView.Distribution.FillEqualy;
StackView.Alignment = TZStackView.Alignment.Fill;
StackView.Spacing = 25;
StackView.Axis = UILayoutConstraintAxis.Vertical;
StackView.TranslatesAutoresizingMaskIntoConstraints = false;

Essentially all I'm trying to do is setup a vertical stackview where the button fill the width of the stackview and space equal vertically with some space, without setting any constraints on the stackview subviews (i.e. the buttons).

image

junk5.zip

Distribution and Alignment enums don't correspond to UIStackView values

Really the title says it all. The values used for the Distribution and Alignment enums don't match up to the values UIStackView expects (to be fair, the original TZStackView also kind of has this problem, except for them the most-commonly-used values do line up, apparently by coincidence!). This makes it much more difficult to use as a drop-in replacement for UIStackView, since the enums have to be converted.

Critical Erro : Foundation.NSObject.xamarin_release_managed_ref

Hey, I'm using TZStackView, I noticed that if I go back and forth from a view containing a StackView, at some point your going to have this error :

2016-04-07 16:16:49.808 MyProject[7208:161052] critical:   at <unknown> <0xffffffff>
2016-04-07 16:16:49.808 MyProject[7208:161052] critical:   at (wrapper managed-to-native) Foundation.NSObject.xamarin_release_managed_ref (intptr,intptr) <0x00012>
2016-04-07 16:16:49.808 MyProject[7208:161052] critical:   at Foundation.NSObject.ReleaseManagedRef () [0x00000] in /Users/builder/data/lanes/2922/f51047c6/source/maccore/src/Foundation/NSObject2.cs:200
2016-04-07 16:16:49.809 MyProject[7208:161052] critical:   at Foundation.NSObject/NSObject_Disposer.Drain (Foundation.NSObject) [0x00062] in /Users/builder/data/lanes/2922/f51047c6/source/maccore/src/Foundation/NSObject2.cs:780

You can prevent this by overriding WillMoveToSuperview in StackView.cs

        public override void WillMoveToSuperview(UIView newsuper)
        {
            if(newsuper == null && this.Subviews != null)
            {
                foreach (var view in this.Subviews)
                {
                    view.RemoveFromSuperview();
                }
            }
            base.WillMoveToSuperview(newsuper);
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.