Skip to content

ZeroOnet/ZExtensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Reasons

Sometimes, we maybe build some views repeatedly. Because we think that they just will be used under a condition. It's the curse of breaking the rule: DRY. In fact, If we are conscious of view's reusing, we will make more efforts to make it completely independent.

So for recording my growth, for writing less codes, for better tomorrow......

I should create this repository to summary some UI(cocoa Touch) extensions that are likely to be used in our work.

List

UIButton

  • Set image alignment:
button.zon.setImage(image, imageAlignment: .top, spacing: 0, state: .normal)

Effect just like this:

bottom image left margin image right margin image top image

UIImage

  • Generate QR code:
QRImageView.image = UIImage.zon.qrImage(content: "我(I) you 🤣", size: CGSize(width: 200, height: 200))

The QR code image as follows:

QR code image

  • Rotate image with degree by clockwise.
  • Compose image with color.
  • Tint image with color.
  • Read gif file.

UIImageView

  • Save image of UIImageView to album by Photos:
imageView.zon.saveImage(completion: @escaping (Result<UIImage, Error>) -> Void)

UIView

  • Edit action:
myLabel.zon.asMenuTrigger([MenuItem(title: "test", action: #selector(testAction))])
  • Get view controller who contains itself by response chain.
  • Shortcuts of frame.
  • Hotspot. Expand or shrink user interaction area with AOP.
let button = UIButton()
// Expand(negative value) or shrink(positive value) extra hotspot area.
button.zon.extraArea = .init(top: 10, left:10, bottom: 10, right: 10)
// Specify minimum positive hotspot size. View will expand its bounds for Hit-Test equally to fit it.
button.zon.minimumSize = .init(width: 44, height: 44)
  • Add gradient layer:
let view = UIView()
let layer = view.zon.gradientLayer // GradationSettable, view will add sublayer automatically.

protocol GradationSettable: AnyObject {
    var locations: [CGFloat] { get set }
    var colors: [UIColor] { get set }
    var startPoint: CGPoint { get set }
    var endPoint: CGPoint { get set }
}
  • Add touchUpInside event action like UIButton with highlighted status:
view.zon.onTouchUpInside(canceller: OutOfBoundsCanceller()) {
    // do something.
}

UIViewController

  • The time interval of browsing view:
scene.zon.enableDurationTrack()
scene.zon.duration
  • Add/Remove child.

UINavigationController

  • Get a visiable navigation controller can push and pop view controller.

UIPasteboard

  • Get/Set sring/image from background queue.

UIStackView

  • Remove all arranged views.
  • Set layout padding and background color.

UITableView

  • Reuse
  • Scroll to bottom.

UICollectionView

  • Reuse
  • Scroll to bottom.

UIColor

  • Init color with hex string like: prefix -> #/0x, suffix -> RGB/RGBA/RRGGBB/RRGGBBAA.

To be continue...

About

Extensions of system API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published