Code Monkey home page Code Monkey logo

neon's Introduction

logo

Build dynamic and beautiful user interfaces like a boss, with Swift.

License Build Status Badge w/ Version Coverage Status Carthage compatible CocoaPods

Neon is built around how user interfaces are naturally and intuitively designed. No more springs and struts. No more whacky visual format language. No more auto layout constraints. We're not robots, so why should we build our UIs like we are?

Neon has been updated to Swift 3.0, but is still currently in beta!

Install via CocoaPods

You can use Cocoapods to install Neon by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!
pod 'Neon'

##Manual Installation

  1. Download and drop /Source in your project.
  2. Congratulations!

To get the full benefits import Neon wherever you have a UIView operation:

import UIKit
import Neon

Example

facebook

Rather than design some arbitrary layout for a demonstration, I figured a good test for the practicality of Neon would be to replicate an existing screen from a major app, one that everyone could recognize. The above screenshot on the left is my profile in the Facebook app, and the screenshot on the right is from the Neon demo project.

Facebook's profile screen was surely built using some form of UITableView or UICollectionView, but for the sake of simple demonstration I built the top-most major components of the profile in a normal UIViewController. After all the customization of the subviews to make them as close to Facebook's design as possible (I tried my best), this is what I came up with for the layout:

let isLandscape : Bool = UIDevice.currentDevice().orientation.isLandscape.boolValue
let bannerHeight : CGFloat = view.height() * 0.43
let avatarHeightMultipler : CGFloat = isLandscape ? 0.75 : 0.43
let avatarSize = bannerHeight * avatarHeightMultipler

searchBar.fillSuperview()
bannerImageView.anchorAndFillEdge(.Top, xPad: 0, yPad: 0, otherSize: bannerHeight)
bannerMaskView.fillSuperview()
avatarImageView.anchorInCorner(.BottomLeft, xPad: 15, yPad: 15, width: avatarSize, height: avatarSize)
nameLabel.alignAndFillWidth(align: .ToTheRightCentered, relativeTo: avatarImageView, padding: 15, height: 120)
cameraButton.anchorInCorner(.BottomRight, xPad: 10, yPad: 7, width: 28, height: 28)
buttonContainerView.alignAndFillWidth(align: .UnderCentered, relativeTo: bannerImageView, padding: 0, height: 62)
buttonContainerView.groupAndFill(group: .Horizontal, views: [postButton, updateInfoButton, activityLogButton, moreButton], padding: 10)
buttonContainerView2.alignAndFillWidth(align: .UnderCentered, relativeTo: buttonContainerView, padding: 0, height: 128)
buttonContainerView2.groupAndFill(group: .Horizontal, views: [aboutView, photosView, friendsView], padding: 10)

portrait

Looks pretty good on every device size! Now, keep in mind you'll probably want constants defined for many of these size/padding values, in order to keep the code cleaner and easier to maintain, but I decided to use real numbers for most of the values to make the code less obscure when new people are reading through the demonstration. Now, unlike Facebook's iPhone app the layout built with Neon is dynamic. It is able to handle rotation on all-sized devices with no problem:

landscape

###Not bad for 10 lines of code!

Here's an intentionally convoluted example to show how easy it is to build very complex and dynamic layouts with Neon. The following layout was created with only 20 lines of code. That's one line of code per view! While impressive, this layout is horrifying and should never be used in an actual app... ever...

Demo

Anchoring Views

Center

There are a few ways you can anchor views using Neon, and the first and most simple is anchoring a view in the center of its superview:

view1.anchorInCenter(width: size, height: size)

Center

Filling Superview

Sometimes you want a view to fill its superview entirely, which couldn't be easier.

view.fillSuperview()

Optionally, if you want a view to fill its superview with padding, you can provide padding instead:

view1.fillSuperview(left: padding, right: padding, top: padding, bottom: padding)

Fill

Corner

The second anchoring method is anchoring a view in its superview's Corner. As you might have guessed, the four corners are .TopLeft, .TopRight, .BottomLeft, .BottomRight, and coupled with the anchorInCorner() function, you can easily anchor a view in any corner like this:

view1.anchorInCorner(.TopLeft, xPad: padding, yPad: padding, width: size, height: size)
view2.anchorInCorner(.TopRight, xPad: padding, yPad: padding, width: size, height: size)
view3.anchorInCorner(.BottomLeft, xPad: padding, yPad: padding, width: size, height: size)
view4.anchorInCorner(.BottomRight, xPad: padding, yPad: padding, width: size, height: size)

Corner

Edge

Edge is another pretty obvious one to follow - it specifies on what edge of its superview a view will be anchored to. The four types are .Top, .Left, .Bottom, or .Right, and similar to previous examples, you can use the anchorToEdge() function to anchor a view to an edge:

view1.anchorToEdge(.Top, padding: padding, width: size, height: size)
view2.anchorToEdge(.Left, padding: padding, width: size, height: size)
view3.anchorToEdge(.Bottom, padding: padding, width: size, height: size)
view4.anchorToEdge(.Right, padding: padding, width: size, height: size)

Edge

Filling an edge

Sometimes, you want to anchor a view against an edge, filling that edge; imagine something like a banner photo for a profile page. Again, this is made as simple as possible using the anchorAndFillEdge() function:

view1.anchorAndFillEdge(.Top, xPad: padding, yPad: padding, otherSize: size)
view2.anchorAndFillEdge(.Bottom, xPad: padding, yPad: padding, otherSize: size)
view3.anchorAndFillEdge(.Left, xPad: padding, yPad: padding, otherSize: size)
view4.anchorAndFillEdge(.Right, xPad: padding, yPad: padding, otherSize: size)

Fill Edge

Note that anchorAndFillEdge() accepts a parameter called otherSize. That parameter is used to set the other size that isn't automatically calculated by filling the edge, meaning that if you specify that you want to anchor to and fill the top edge, the width will be automatically calculated, but the height is still unknown, so the value passed in to otherSize will be used to set the height. Subsequently, if you want to anchor to and fill the left edge, the height is automatically calculated and otherSize will be used to set the width of the view.

Align

Now that we've anchored primary views, we can start making our UI more complex by aligning other views relative to other sibling views, using the (you guessed it) Align value. Sibling views are views that share the same superview directly. There are twelve Align types, and they are all pretty self-explanatory - here's an example using all twelve with the align() function:

view1.align(.AboveMatchingLeft, relativeTo: anchorView, padding: padding, width: size, height: size)
view2.align(.AboveCentered, relativeTo: anchorView, padding: padding, width: size, height: size)
view3.align(.AboveMatchingRight, relativeTo: anchorView, padding: padding, width: size, height: size)
view4.align(.ToTheRightMatchingTop, relativeTo: anchorView, padding: padding, width: size, height: size)
view5.align(.ToTheRightCentered, relativeTo: anchorView, padding: padding, width: size, height: size)
view6.align(.ToTheRightMatchingBottom, relativeTo: anchorView, padding: padding, width: size, height: size)
view7.align(.UnderMatchingRight, relativeTo: anchorView, padding: padding, width: size, height: size)
view8.align(.UnderCentered, relativeTo: anchorView, padding: padding, width: size, height: size)
view9.align(.UnderMatchingLeft, relativeTo: anchorView, padding: padding, width: size, height: size)
view10.align(.ToTheLeftMatchingBottom, relativeTo: anchorView, padding: padding, width: size, height: size)
view11.align(.ToTheLeftCentered, relativeTo: anchorView, padding: padding, width: size, height: size)
view12.align(.ToTheLeftMatchingTop, relativeTo: anchorView, padding: padding, width: size, height: size)

Align

Align and fill

You don't always know or want to specify the size of a view that you want to layout relative to another, but rather you want to either fill the width, height, or the entire rest of the superview, after aligning with the sibling. Combined with all the different alignment types discussed earlier, we're starting to see how more complex layouts can be built very easily:

view2.alignAndFillWidth(align: .ToTheRightMatchingTop, relativeTo: view1, padding: padding, height: size / 2.0)
view4.alignAndFillHeight(align: .AboveCentered, relativeTo: view3, padding: padding, width: size / 2.0)
view6.alignAndFill(align: .ToTheLeftMatchingTop, relativeTo: view5, padding: padding)

Align Fill

Align between

Sometimes you want a view to sit between to other views, filling the space between them. Using alignBetweenHorizontal() and alignBetweenVertical(), doing that is super easy! Choose one of your sibling views you want to align your view relative to and pass that in as your primaryView. We will use the specified align parameter to match that primaryView appropriately, and automatically fill either the horizontal or vertical span between the it and the secondaryView.

view1.alignBetweenHorizontal(align: .ToTheRightMatchingTop, primaryView: anchorViewA, secondaryView: anchorViewB, padding: padding, height: size)
view2.alignBetweenVertical(align: .UnderCentered, primaryView: anchorViewB, secondaryView: anchorViewD, padding: padding, width: size)
view3.alignBetweenHorizontal(align: .ToTheLeftMatchingBottom, primaryView: anchorViewD, secondaryView: anchorViewC, padding: padding, height: size)
view4.alignBetweenVertical(align: .AboveMatchingRight, primaryView: anchorViewC, secondaryView: anchorViewA, padding: padding, width: size)

Align Between Fill

What about labels?

One of the more complicated parts of working with dynamic layouts, is dealing with labels that may have 1 -> n lines, and as such passing in a specific height isn't always possible without causing a migraine. Neon makes this easy by introducing the AutoHeight constant. Pass this value into methods that accept a height param, and we will first set the width of the frame, tell the view to sizeToFit() so the height is automatically set based on its contents, and then align the view appropriately. For example:

testLabel.alignBetweenHorizontal(align: .ToTheRightMatchingBottom, primaryView: anchorViewA, secondaryView: anchorViewB, padding: padding, height: AutoHeight)

Auto Height 1

Note that changing the text to something with more characters still produces the same desired result:

Auto Height 2

It's important to note that the using AutoHeight with something like a CALayer, or passing it in to any of the grouping methods (see below) will have undesired consequences, as it almost doesn't make sense in this context. Use AutoHeight with anything that implements sizeToFit() and you should be OK. The vast majority of cases where you'll want to use this is with UILabel objects.

What if I don't want to align them perfectly?

Sometimes you don't want your views to align with their sibling views exactly - you may want to align them relative to their siblings, but with a slight offset. You can do this by adding the optional offset parameter to any of the above align methods to produce something like the following:

view1.align(.ToTheRightMatchingTop, relativeTo: anchorViewA, padding: padding, width: size, height: size, offset: offset)
view2.align(.UnderMatchingLeft, relativeTo: anchorViewA, padding: padding, width: size, height: size, offset: offset)

Offset

Grouping

Another common use-case is the grouping of sibling views, aligned in a row or column. Using what we've already learned about anchoring views in the center, in a corner, or against an edge, we can also do the same with groups of views!

The primary difference with grouping, is that it is done by the parent view, or superview of a group of views. For example, let's let two different views center a group of their subviews in each of the two different Group configurations, .Horizontal and .Vertical:

anchorViewA.groupInCenter(group: .Horizontal, views: [view1, view2, view3], padding: padding, width: size, height: size)
anchorViewB.groupInCenter(group: .Vertical, views: [view4, view5, view6], padding: padding, width: size, height: size)

Group in center

How about grouping views in the corner?

anchorViewA.groupInCorner(group: .Horizontal, views: [view1, view2, view3], inCorner: .TopLeft, padding: padding, width: size, height: size)
anchorViewB.groupInCorner(group: .Vertical, views: [view4, view5, view6], inCorner: .BottomRight, padding: padding, width: size, height: size)

Group in corner

As you might have expected, you can also group either horizontally and vertically against any edge as well:

anchorViewA.groupAgainstEdge(group: .Horizontal, views: [view1, view2, view3], againstEdge: .Left, padding: padding, width: size, height: size)
anchorViewB.groupAgainstEdge(group: .Vertical, views: [view4, view5, view6], againstEdge: .Bottom, padding: padding, width: size, height: size)

Group against edge

Grouping views relative to a sibling view can be done as well:

view.groupAndAlign(group: .Horizontal, andAlign: .ToTheRightMatchingTop, views: [view1, view2, view3], relativeTo: anchorViewA, padding: padding, width: size, height: size)
view.groupAndAlign(group: .Vertical, andAlign: .UnderCentered, views: [view4, view5, view6], relativeTo: anchorViewA, padding: padding, width: size, height: size)

Group relative

You can also specify that you want a group of subviews to fill their superview, either horizontally or vertically:

anchorViewA.groupAndFill(group: .Horizontal, views: [view1, view2, view3], padding: padding)
anchorViewB.groupAndFill(group: .Vertical, views: [view4, view5, view6], padding: padding)

Group and fill

License

The source is made available under the MIT license. See LICENSE.txt for details.

neon's People

Contributors

basthomas avatar bhendersonizeni avatar esqarrouth avatar icykira avatar idurian avatar lexrus avatar mamaral avatar moonko avatar nhojb avatar pedrovereza avatar tim12s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neon's Issues

Carthage Build App Store Submission Bug

When I use Neon via Carthage in my app and upload it to iTunes Connect, I get the following email from Apple:

Dear developer,

We have discovered one or more issues with your recent delivery for "Wispeo". To process your delivery, the following issues must be corrected:

Invalid Bundle - Do not submit apps with GCC-style coverage instrumentation enabled. Specifically, the following Xcode build settings should be disabled: Instrument Program Flow Generate Test Coverage Files

Once these issues have been corrected, you can then redeliver the corrected binary.

Regards,

The App Store team

The email should have a comma between "Instrument Program Flow" and "Generate Test Coverage Files."

Can we just disable these build options? I'm not sure why they'd be needed in the first place.

After aligning the UIscrollview, the subview cant be shown and not scrollable

Dear Sir,

Thanks for making this features. They are awesome! Hope more and more people use yours masterpiece. It's very useful. 👍 👍 👍 👍

However, for the UIscrollview, the subview cant be shown and not scrollable. Do you have any procedures to include the subview of UIscrollview or how to make the scrollview to be scrollable?

Thanks a lot! Looking forward to hearing from yours :)
Best Regards,
JC

enums to OptionSets

Right now:

avatarImageView.anchorInCorner(.BottomLeft, xPad: 15, yPad: 15, width: avatarSize, height: avatarSize)

could be:

avatarImageView.anchorInCorner([.Bottom, .Left], xPad: 15, yPad: 15, width: avatarSize, height: avatarSize)

Example of bitmask/option sets/flags in Swift 2.0:

struct MyOptions : OptionSetType {
    let rawValue: Int

    static let None         = MyOptions(rawValue: 0)
    static let FirstOption  = MyOptions(rawValue: 1 << 0)
    static let SecondOption = MyOptions(rawValue: 1 << 1)
    static let ThirdOption  = MyOptions(rawValue: 1 << 2)
}

let singleOption = MyOptions.FirstOption
let multipleOptions: MyOptions = [.FirstOption, .SecondOption]
if multipleOptions.contains(.SecondOption) {
    print("multipleOptions has SecondOption")
}
let allOptions = MyOptions(rawValue: 7)
if allOptions.contains(.ThirdOption) {
    print("allOptions has ThirdOption")
}

Propose grouping without explicit size

Hello,
I would like to propose idea of grouping without calculating the size of the group explicitly. In that case, Neon should call sizeToFit on each of the subviews and calculate the total size.
In addition to

anchorViewA.groupInCenter(group: .Horizontal, views: [view1, view2, view3], padding: padding, width: size, height: size)

there would be this option

anchorViewA.groupInCenter(group: .Horizontal, views: [view1, view2, view3], padding: padding)

How do you feel about it?

The reason behind this feature is to group multiple items that are of different size.

Support right-to-left languages

I think a little bit about that.
As a basis idea we can take AutoLayout approach:
.leading means .left on left-to-right languages and means .right on right-to-left languages;
.trailing means .right on left-to-right languages and means .left on right-to-left languages.

We can implement this by simple adding factory functions to our enums(Edge, Corner, Align), for example for Edge:

public enum Edge {
    case top
    case left
    case bottom
    case right

    static func leading() -> Edge {
        return isRightToLeft() ? .right : .left
    }

    static func trailing() -> Edge {
        return isRightToLeft() ? .left : .right
    }
}

Then if client code wants to respect language direction, it should use .leading() and .trailing() functions instead .left and .right:

func isRightToLeft() -> Bool {
//    return UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
    return true
}

func bar(edge: Edge) {
    switch edge {
    case .left:
        print("left")
    case .right:
        print("right")
    case .top:
        print("top")
    case .bottom:
        print("bottom")
    }
}

bar(edge: .leading()) // prints 'right'

@mamaral what you think about this approach? Any suggestions?

AutoHeight doesn't work if UILabel text is set after the constraints are made.

For example, this will only display a label with a height large enough for "Hello World".

        let label : UILabel = UILabel()
        self.view.addSubview(label)
        
        label.textColor = .black
        label.numberOfLines = 0
        label.lineBreakMode = .byWordWrapping
        
        label.text = "Hello world"
        label.anchorAndFillEdge(.bottom, xPad: 24, yPad: 24, otherSize: AutoHeight)
        label.text = "asdfn aksdjhf akjsdhf kajhsd fkjhasd fkjhads kjfha sdkjhf akjsdhf akjshdf kajhsdf kjhasd fkh ckhsd chjsdfkv hjsdfv ksjdhfv ksjhdfv kjshdf vkjshdf vkjhsdf end"

error while carthage update

I add the neon to my Cartfile,but while Im run carthage update commond,terminal show an error:

  *** Fetching Neon
  *** Checking out Neon at "v0.0.2"
  *** xcodebuild output can be found in /var/folders/5y/x8t9wb3d1t33b77ckz509p_w0000gn/T/carthage-xcodebuild.JEhAhQ.log
 A shell task failed with exit code 66:
 xcodebuild: error: Scheme NeonMacDemo is not currently configured for the build action.

Installing with Carthage - build failed

When I attempt to install this framework with Carthage, the build fails with the following output:

.../Carthage/Checkouts/Neon/Source/Neon.swift:30:9: error: value of type 'View'
(aka 'NSView') has no member 'sizeToFit'                                                                             
A shell task failed with exit code 65:                                                                               
** BUILD FAILED **

has anyone found a workaround for this (besides installing it as a module)?

Using Neon in a custom view xib?

I saw one other issue like that (unfortunately with no follow-up by the OP). I am hoping to create a custom nib-based view to drop into a main view, and each instance will manage its own layout via neon (liking the repo!). But, there is absolutely no neon-action within the instantiation. I have the most basic of view, and simply firing it up within the main VC, and dropped a sample view that is instructed to fill its container. I set the colors to show me it works. It does not. Wondering if you have tried something similar?

Paddings -> offsets

Wouldnt it be fitting to refactor xPad: CGFloat, yPad: CGFloat type arguments to something nice like offset: CGSize and/or offset: UIEdgeInsets. Seems a bit nicer to me, or at least provide it as overloads to current implementation :)

Dynamic UIlabel

It's not a issue just a suggestion. at the moment I have UILabels that can have 1 to 2 lines depending and text size.

at the moment I do this like this but I'm sure there is a better way

let nameLabelHeight = nameLabel.text?.heightWithConstrainedWidth(self.width - 24 - profilePictureImageView.width, font: nameLabel.font)
    if let n = nameLabelHeight where n > 60 {
        nameLabel.alignAndFillWidth(align: .ToTheRightMatchingTop, relativeTo: profilePictureImageView, padding: 8, height: 60)
    } else if let n = nameLabelHeight {
        nameLabel.alignAndFillWidth(align: .ToTheRightMatchingTop, relativeTo: profilePictureImageView, padding: 8, height: n)
    }

Views array fatal error

        var views:[UIView] = []
        let view1 = UIView()
        view1.backgroundColor = UIColor.redColor()
        let view2 = UIView()
        view2.backgroundColor = UIColor.greenColor()

        view.addSubview(view1)
        view.addSubview(view2)

        views.append(view1)
        views.append(view2)

        view.groupAndFill(group: .Horizontal, views: views, padding: 10)

fatal error: array cannot be bridged from Objective-C

set the xPad and yPad to zero as default value

I have an idea:
set the xPad and yPad to zero as default value.so that we can have an api that needn't pass the xPad and yPad if xPad is 0 and yPad is 0 .
because almost every API in Neon contains parameters of xPad and yPad,and almost every time I pass zero to them.If the default value is Zero,I will needn't pass zero any more.
My code will be nicer~

Prefix the methods

Hi,
I think it would be a good idea to prefix every methods you have added to UIView.
It would be simpler for others people to find / discover your methods.

iOS 11

I really like this library and its simplicity in layouts. Is there any plans to update?

Question: How is animation with neon?

I just saw the library, didn't dig into it much, but hopefully considering to use it. Just one concern, how is the basic animations with neon, what are the animation properties? Like with autolayout you animate the constraints constants which is a pain in the ass rather than normal uiview animations.

If the animation is breeze I'm all on with this layout system :)
👍

20 lines of code

In the meantime, here's an intentionally convoluted example to show how easy it is to build very complex and dynamic layouts with Neon. The following layout was created with only 20 lines of code.

Can we see this code? Thanks.

Allow setting xPad, yPad individually for groupAgainstEdge

Hello,

I am currently using the groupAgainstEdge method to group 3 dots together, aligned at the bottom edge, like so:

view.groupAgainstEdge(group: .Horizontal, views: [pageIndexCircles[0], pageIndexCircles[1], pageIndexCircles[2]], againstEdge: .Bottom, padding: 10, width: 10, height: 10)

The limitation is that the padding determines both the vertical padding from the bottom /and/ the horizontal padding of the dots together. E.g., if I increase the padding value, the dots move further away from the bottom edge and further away from each other. I assume this is a simple oversight in an otherwise amazing framework. Being able to specify the horizontal/vertical padding separately for groupAgainstEdge (where, depending on if the group is .Horizontal or .Vertical, the xPad will control the spacing between the elements of the group and yPad the distance from the edge, and vice-versa).

Thanks very much.

Support Swift Package Manager

Given GitHub and Xcode now have integrations with the SPM, it would be good to support it, so the library is easy to integrate.

Support for safeArea Layout with iOS 11/iPhone X ?

With the release of iPhone X, apps that use Neon are working without runtime issues, but since the iPhone X has some interesting physical attribute it will be great if Neon could add support for the safeArea layout that is now available. Neon should support the safe area at the top for avoiding any issue with the "notch" of the iPhone X, and since the bottom area with the iPhone X has the visible UI element for dragging up it will be good to have some updated API that could account for it.

Button click action is not working

Hi,
In TwitterProfileExampleViewController, i add a click event to cameraButton which is an UIButton, but the click action is not working. Can you help me please. thanks

` cameraButton.setImage(UIImage(named: "camera"), for: .normal)
cameraButton.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)

func buttonAction(sender: UIButton!) {
    var btnsendtag: UIButton = sender
    if btnsendtag.tag == 1 {
        //do anything here
    }
}

`

StackFillEdge?

Perhaps i am missing this, or perhaps my suggested name is not quite right but my basic use case causes me to introduce container views to achieve my layout. It is similar to building a table row by row: the first view must fill top width, then the next one must fill the next top width below it and so on. Grouping top left than calculating width could work but the adding of the elements can be staggering in time.

Perhaps this is already easy and I am just missing how? thx..

Awesome repo btw!!

Update to Swift 3

Already noticed a lot of updates are required. I may try to update some of the stuff, but I'm really busy at the moment. What are the plans to update Neon to Swift v3?

Cannot do layout with transform

If this property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.

from apple documentation

And if you use any transform on your own view, you cannot do layout with Neon methods

I suggest set transform to "Indentity" before layout and return after in all Neon methods

keep aspect-ratio of view

I might just not see it, but is there any way to implement a dynamically sized view that keeps its aspect-ratio?

Best Regards

Autolayout question

Hey there,

I was wondering what this is using under the hood? Are we able to "mix and match" auto layout constraints via Storyboard and Neon for some other views?

Thanks and great job with this!

Use Legacy Swift Language Version

I getting issue like this using carthage

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

Bump podspec to '0.3.4.4'

The latest release is '0.3.4.4', however, in podspec the version is '0.3.4.3', which is incorrect.
Please fix it.

How to autoheight UITableViewCell?

When i use Neon,I can't use this gramera to autoHeight UITableViewCell
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 300

Could you fix the problem?
Thank you.

How to layout a table with equal cell height and width?

Give a resizable UIView, what is the proper way to layout a 3 x 4 table with equal width and height for each cell?

For example, when the view is 120 x 120, each cell is 40 x 30. When the view is resize to 240 x 360, each cell changes to 80 x 90.

wrong height while overriding updateConstraints using AutoHeight

I am overriding updateConstraints in the init, and first I have a wrong height (too much) for the labels I have aligned, and only after three times (idk why it calls it three times) accessing a function updateConstraints it gives right height. It is better to understand showing the code.

override func updateConstraints() {
        locationLabel.anchorToEdge(.top, padding: 0, width: self.frame.width, height: AutoHeight)
        seasonLabel.align(.underCentered, relativeTo: locationLabel, padding: 0, width: self.frame.width, height: AutoHeight)
        seasonLabel.alignAndFillWidth(align: .underCentered, relativeTo: locationLabel, padding: 0, height: AutoHeight)
        quantityLabel.alignAndFillWidth(align: .underCentered, relativeTo: seasonLabel, padding: 0, height: AutoHeight)
        durationLabel.alignAndFillWidth(align: .underCentered, relativeTo: quantityLabel, padding: 0, height: AutoHeight)
        requirementsLabel.align(.underMatchingLeft, relativeTo: durationLabel, padding: 0, width: self.frame.width*0.9, height: self.labelHeight)
        height = locationLabel.frame.height+seasonLabel.frame.height+quantityLabel.frame.height+durationLabel.frame.height+self.labelHeight
        print (height)
    }

In the console I have:

1306.0
1348.0
479.0

And here first two heights are too big (wrong), and the last one is right. How can I get only the last one?

AsyncDisplayKit

I saw in some issue in Facebooks ASDK that someone wanted to use Neon with ASDK. They told him it would be difficult to implement but I think its as easy as

extension ASDisplayNode : Frameable, Anchorable, Alignable, Groupable {
    public var superFrame: CGRect {
        guard let supernode = supernode else {
            return CGRectZero
        }

        return supernode.frame
    }
}

Isn't it?

UILabel width

Hi,

Great work on making a super flexible and simple layout framework.

Any chance you can have tried to have UIButton and UILabel to automatically calculate their widths as per below where the width of a button/label can be calculated from its contents?

button1.anchorInCornerAndUseWidth(.BottomLeft, xPad: 20, yPad: 20, height: 30)
label2.alignAndUseWidth(align: .ToTheRightMatchingTop, relativeTo: button1, padding: 20, height: 30)
button3.alignAndFillWidth(align: .ToTheRightMatchingTop, relativeTo: label2, padding: 20, height: 30)

Thanks for the elegant work,
-Tim

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.