TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by Dominik Butz.
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.
To run the example project, clone the repo, and run pod install
from the Example directory first.
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
Check out the following examples.
@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)
}
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)
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
Minor changes after conversion to Swift 4.0 (the code didn't require any conversion).
moving setup of label to draw(rect:)
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.
extended documentation
Using cocoapods template to re-create the project.
Released on 2017-04-12. First release!
dominikbutz, [email protected]
DYCornerBanner is available under the MIT license. See the LICENSE file for more info.