Giter Site home page Giter Site logo

ios-custom-alertview-swift's Introduction

Custom iOS7 AlertView

The addSubview method is not available in UIAlertView in iOS7 any more. The view hierarchy for this class is private and must not be modified.

As a solution, this class creates an iOS7-style AlertView for which you can supply your own buttons and UIView for the content. The animations and the looks are copied too and no images or other resources are needed.

A demo screen

Installation

It's as simple as adding the following file to your project:

Support

Only iOS 7 and newer.

Quick start guide

  1. Create a CustomIOS7AlertView instance:
let alertView = CustomIOS7AlertView()
  1. Add some custom content to the alert view:
alertView.containerView = UIView(...)
  1. Set a callback

Using a delegate: (see the properties for the protocol)

alertView.delegate = self

Or a closure:

alertView.onButtonTouchUpInside = {
  (alertView: CustomIOS7AlertView, buttonIndex: Int) -> Void in

  println("Closure says: Button with index \(buttonIndex) has been touched!")
}
  1. Display the alertView:
alertView.show()

Functions

  • show() Shows the alertView

  • show(completion: ((Bool) -> Void)?) Shows the alertView then runs completion

  • close() Closes the alertView

  • close(completion: ((Bool) -> Void)?) Closes the alertView then runs completion

  • setButtonEnabled(enabled: Bool, buttonName: String) Enables or disables a button. Make sure you call this after show()

Properties

  • buttonHeight: CGFloat The height of the buttons. Default: 50

  • buttonsDividerHeight: CGFloat The height of the buttons divider. Default: 1

  • cornerRadius: CGFloat The radius of the alert view. Default: 7

  • useMotionEffects: Bool Whether to use motion effects or not. Default: true

  • motionEffectExtent: Int The extent of the motion effects. Default: 10

  • containerView: UIView! The custom view to show. By default this is an empty view.

  • buttonTitles: [String]? An array of strings. Each string will be a button. Default: ["Close"]

  • buttonColor: UIColor? The color of the buttons in normal state. By default this is the UIButton's default tintColor

  • buttonColorHighlighted: UIColor? The color of the buttons in normal state. By default this the same as buttonColor but with an alpha of 0.5

  • delegate: CustomIOS7AlertViewDelegate? A delegate that implements the CustomIOS7AlertViewDelegate protocol below. nil by default.

protocol CustomIOS7AlertViewDelegate: class {
  func customIOS7AlertViewButtonTouchUpInside(alertView: CustomIOS7AlertView, buttonIndex: Int)
}
  • onButtonTouchUpInside: ((alertView: CustomIOS7AlertView, buttonIndex: Int) -> Void)? A closure that is called when a button is touched. nil by default.

License

Please feel free to push back anything you think is useful for the project.

Copyright (c) 2013 Richard Dancsi

Lincesed under The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ios-custom-alertview-swift's People

Contributors

wimagguc avatar dingosky avatar mohammedj avatar scorpiozj avatar

Watchers

James Cloos avatar  avatar  avatar

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.