All Projects → wordlessj → Panda

wordlessj / Panda

Licence: MIT license
Create view hierarchies declaratively.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Panda

Mindo
Generate mind maps easily in your android app.
Stars: ✭ 52 (-24.64%)
Mutual labels:  view, hierarchy
VRCalendarView
Flexible calendar view
Stars: ✭ 33 (-52.17%)
Mutual labels:  view
Riot
Simple and elegant component-based UI library
Stars: ✭ 14,596 (+21053.62%)
Mutual labels:  view
FeedbackAnimSample
An attempt to code feedback animation UI inspired from https://site.uplabs.com/posts/web-feedback
Stars: ✭ 57 (-17.39%)
Mutual labels:  view
Slidemenulayout
🔥An android slide menu that supports left and right swipes and slides with parallax.(一个支持左右滑动并带有视差滑动效果的安卓侧滑菜单控件.仿[QQ/探探侧滑])
Stars: ✭ 235 (+240.58%)
Mutual labels:  view
ShadowStackView
Create something like Shadow-View animation when drag the view on screen
Stars: ✭ 25 (-63.77%)
Mutual labels:  view
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (+226.09%)
Mutual labels:  view
react-native-math-view
Math view for react native! No WebView!
Stars: ✭ 49 (-28.99%)
Mutual labels:  view
mysql-interview-questions
SQL Basics
Stars: ✭ 202 (+192.75%)
Mutual labels:  view
ViewWorld
自定义View合集,展示各种自定义View/控件。项目包含了自定义Banner轮播图控件,自定义验证码输入框,自定义TabLayout等控件,持续更新中😉😉😉
Stars: ✭ 94 (+36.23%)
Mutual labels:  view
vanillaview
Easy to use views with vanilla JS semantics
Stars: ✭ 12 (-82.61%)
Mutual labels:  view
Viewanimator
A fluent Android animation library
Stars: ✭ 2,656 (+3749.28%)
Mutual labels:  view
bottomsheets
Material Bottom Sheets library for Android
Stars: ✭ 76 (+10.14%)
Mutual labels:  view
Shadowimageview
🔥可以根据图片内容变阴影颜色,更加细腻的阴影效果 It can change color according to the picture, more delicate shadow effect
Stars: ✭ 2,560 (+3610.14%)
Mutual labels:  view
MultiModal
Use multiple .sheet, .alert, etc. modifiers in the same SwiftUI View
Stars: ✭ 49 (-28.99%)
Mutual labels:  view
Laravel Tag Helper
Add powerful HTML tag helpers to your Laravel application
Stars: ✭ 227 (+228.99%)
Mutual labels:  view
angular-calendar-week-hours-view
This is an alternative week view for the angular calendar which allows the user to see all the week hours
Stars: ✭ 20 (-71.01%)
Mutual labels:  view
andColorPicker
Color picker library for Android
Stars: ✭ 233 (+237.68%)
Mutual labels:  view
ProgressableImageView
Change your users progress capability with ProgressableImageView
Stars: ✭ 86 (+24.64%)
Mutual labels:  view
EasyView
🔥🔥🔥一个小巧美观,支持圆角,描边,阴影的 Android 控件库,极度轻量,支持代码动态修改圆角、描边!
Stars: ✭ 48 (-30.43%)
Mutual labels:  view

Panda


Carthage Compatible CocoaPods Compatible Swift 5 Platform Build Status

Create view hierarchies declaratively.

Quick Look

view.pd.add(
    imageView.pd.image(logoImage),
    label.pd.text("Logo").textColor(.red).font(size: 20),
    button.pd.title("Go").action(buttonTapped)
)

It’s much shorter and concise than the imperative API, and easier to edit than storyboards.

Installation

Carthage

github "wordlessj/Panda" ~> 2.0

CocoaPods

pod 'Panda', '~> 2.0'

Usage

Basics

ALL settable properties and set methods in UIKit and Core Animation are available in pd extension, set prefixes are removed.

Views are configured and added to a superview as you see in Quick Look, you can also nest add() to create a more complex hierarchy, note that configuration by pd is optional.

view.pd.add(
    containerView.pd.clipsToBounds(true).add(
        view1.pd.backgroundColor(.red)
    ),
    view2
)

Other types that can be added by add*() methods are also supported, like UIGestureRecognizer and UILayoutGuide. Don’t put them all in one add() method, grouping is recommended.

view.pd.add(
    // view hierarchy
).add(
    layoutGuide.pd.identifier("center guide")
).add(
    tapGestureRecognizer.pd.numberOfTapsRequired(2).action(doubleTapped)
)

Objects can be configured inline and passed to a method, if the method accepts a *Convertible.

// mask() accepts a UIViewConvertible.
// You can pass a plain or configured UIView.
view.pd.mask(
    maskView.pd.backgroundColor(.white)
)

Add and Remove

add() and remove() methods are available on types below, followed by types that can be added. remove() is basically used to remove multiple object at once without configuration.

Type Types which can be added
CALayer CALayer, CAAnimation
UIAlertController UIAlertAction, UIViewController, UIKeyCommand
UIDynamicAnimator UIDynamicBehavior
UIDynamicBehavior UIDynamicBehavior
UIView UIView, UIGestureRecognizer, UIMotionEffect, NSLayoutConstraint, UILayoutGuide, UIInteraction
UIViewController UIViewController, UIKeyCommand

UIView is added to UIStackView using addArrangedSubview().

Custom Properties

With smart key paths, you can use set() to set custom properties not found in Panda.

customView.pd.set(\.flashes, true)

Action

Target-actions are replaced with action() taking a closure. They’re available on following types.

  • CADisplayLink, an initializer instead of action().
  • UIAccessibilityCustomAction
  • UIBarButtonItem
  • UIControl
  • UIGestureRecognizer

Font

UIFont factory methods are available directly as following methods.

  • font(style:)
  • font(style:compatibleWith:)
  • font(size:)
  • font(size:weight:)
  • font(boldSize:)
  • font(italicSize:)
  • font(monospacedDigitSize:weight:)

They’re available on following types.

  • UIButton, set font of titleLabel.
  • UILabel
  • UISimpleTextPrintFormatter
  • UITextField
  • UITextView

Transform

There’re several convenient methods to set transform on UICollectionViewLayoutAttributes and UIView. Each of them has a corresponding concat*() method to concatenate a transform to existing transform.

  • rotation(radian:)
  • rotation(degree:)
  • scale(x:y:)
  • scale(_:)
  • translation(x:y:)

Control States and Bar Metrics

For set methods taking a UIControlState or UIBarMetrics like title(_:for:), there’re convenience methods to set for all states or metrics like title(_:highlighted:selected:disabled:), the first parameter is for normal state, and the other parameters are optional.

Compositions

For convenience, there’re several composition methods which set multiple properties at once.

Types Composition Components
CALayer border borderWidth, borderColor
CALayer shadow shadowOpacity, shadowRadius, shadowOffset, shadowColor, shadowPath
UICollectionView, UIPageViewController, UIPickerView, UITableView sourceDelegate dataSource, delegate
UILabel shadow shadowColor, shadowOffset
UIScrollView alwaysBounce alwaysBounceHorizontal, alwaysBounceVertical
UIScrollView showsScrollIndicators showsHorizontalScrollIndicator, showsVerticalScrollIndicator
UIView border layer.border
UIView cornerRadius layer.cornerRadius, layer.masksToBounds to true
UIView shouldRasterize layer.shouldRasterize, layer.rasterizationScale to screen's scale
UIView shadow layer.shadow

Set-Like Methods

Some methods don’t begin with set but are usually called while configuring, they are available as well.

  • UIAlertController.pd.addTextField(configure:)
  • UIGestureRecognizer.pd.require(toFail:)

Register and Dequeue

For UICollectionView and UITableView, an identifier is required when registering and dequeuing cells and views, and force casting to a specific type is usually needed. In practice, one identifier is associated with one specific type, so you can use the type itself instead of an identifier.

collectionView.pd.register(CustomCell.self)

let cell: CustomCell = collectionView.pd.dequeue(CustomCell.self, for: indexPath)

Reuse

If more than one object share similar configurations, or you want to create something like CSS, you can extract configurations into a method, then apply the method using do().

view.pd.add(
    firstLabel.pd.do(configLabel),
    secondLabel.pd.do(configLabel)
)

func configLabel(_ label: UILabel) {
    label.pd.textColor(.red).font(size: 20).numberOfLines(0)
}

Bamboo

Bamboo is a framework which makes Auto Layout and manual layout in one line, together with Panda, they make creating views in code incredibly simple and easy.

License

Panda is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].