DYCornerBanner 1.1.3

DYCornerBanner 1.1.3

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Dominik Butz.




  • By
  • dominikbutz

DYCornerBanner written in allows you to quickly create corner labels on top of any kind of rectangular view, e.g. UIImageView. The rotation angle of the corner label is determined by the width and height of the banner view.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Features

  • set the corner position to bottom right, top right, top left or bottom left.
  • supports banners in any rotation angle and distance from the corner - the rotation angle and the distance from the corner are determined by the size and height-width proportion of the DYCornerBanner view frame.
  • override the default setting for the banner width.
  • override the default setting for the banner text font.

Installation

DYCornerBanner is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DYCornerBanner'

Make sure to import DYCornerBanner into your View Controller subclass:

import DYCornerBanner

Usage

Check out the following examples.

DYCornerBanner examples

Code example: Creating a DYCornerBanner from Interface Builder

 @IBOutlet weak var cornerBannerBottomLeft: DYCornerBanner!  // simply drop a UIView into the VC from interface builder in storyboard  and set the UIView class to DYCornerBanner
 

 override func viewDidLoad() {
   super.viewDidLoad()
   
   self.cornerBannerBottomLeft.setup(text: "Sunshine Guaranteed!", textColor: 	UIColor.black, bannerColor: UIColor.yellow, position: .bottomLeft)
   
 }

Code example: Creating a DYCornerBanner in code

Alternatively, you can create a corner banner instance in code like so:

   let frame = CGRect(x: self.imageView.frame.size.width -  90, y: 0, width: 90, height: 90)
   let bannerInCode = DYCornerBanner(frame: frame)
   bannerInCode.setup(text: "Free Cocktails!", textColor: UIColor.red, bannerColor: UIColor.white.withAlphaComponent(0.6), position: .topRight)
  self.imageView.addSubview(bannerInCode)

Customising

You can override the settings for bannerWidth and textFont as shown below.

self.cornerBannerTopLeft.setup(text: "Just Added!", textColor: UIColor.white, bannerColor: UIColor.grassGreen(), position: .topLeft)

self.cornerBannerTopLeft.textFont = UIFont(name: "ChalkboardSE-Bold" , size: 15.0)!
self.cornerBannerTopLeft.bannerWidth = 17.0

Change log

Version 1.1.2

Minor changes after conversion to Swift 4.0 (the code didn't require any conversion).

Version 1.1.1

moving setup of label to draw(rect:)

Version 1.1

banner width (=label height) set explicitly now, not any more by creating a dummy label and using its height. text font and banner width can now be overridden after or before calling setup.

Version 1.0.3

extended documentation

Version 1.0.2

Using cocoapods template to re-create the project.

Version 1.0

Released on 2017-04-12. First release!

Author

dominikbutz, [email protected]

License

DYCornerBanner is available under the MIT license. See the LICENSE file for more info.