Giter VIP home page Giter VIP logo

candostdagdeviren / cdalertview Goto Github PK

View Code? Open in Web Editor NEW
1.1K 28.0 82.0 1.32 MB

Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

Home Page: https://candostdagdeviren.github.io/CDAlertView/

License: MIT License

Ruby 3.53% Swift 95.35% Objective-C 1.11%
popup alert alert-messages alertview alerts warning popup-window carthage cocoapods swift5

cdalertview's Introduction

CDAlertView: Highly customizable alert popup

Carthage compatible Cocoapod CI Status Language Platform License

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController.

Screenshots

CDAlertView Types

Animations

1 2 3

Usage

Basic usage without any buttons:

CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .notification).show()

NOTE: You can use it without buttons. Touch outside of the popup or move it will disappear it if there is no action button. If there is an action button, only pressing button will disappear it.

To add new buttons:

let alert = CDAlertView(title: "Awesome Title", message: "Are you in?!", type: .notification)
let doneAction = CDAlertViewAction(title: "Sure! πŸ’ͺ")
alert.add(action: doneAction)
let nevermindAction = CDAlertViewAction(title: "Nevermind πŸ˜‘")
alert.add(action: nevermindAction)
alert.show()

To enable text field in popup:

alert.isTextFieldHidden = false

Custom view is also supported. If you want to use custom view, you are responsible for the height of custom view. Custom view is used in UIStackView.

let myCustomView = UIVIew(frame: myFrame)
// Don't forget to handle height of `myCustomView`
alert.customView = myCustomView

CDAlertView types:

public enum CDAlertViewType {
    case error, warning, success, notification, alarm, noImage, custom(image:UIImage)
}

Initialization

Advanced Alert Initialization

To use it with your custom icon, initialize without type (or with .empty) and set your icon and background color:

let alert = CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .custom(image: UIImage(named:"YourAwesomeImage")))
alert.circleFillColor = UIColor.yourAmazingColor

Hide Alert with your animation

let alert = CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .success)
alert.hideAnimations = { (center, transform, alpha) in
    transform = CGAffineTransform(scaleX: 3, y: 3)
    alpha = 0
}
alert.hideAnimationDuration = 0.88
alert.show()

Hide Alert with timer

let alert = CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .success)
alert.autoHideTime = 4.5 // This will hide alert box after 4.5 seconds

List of Available CDAlertView Options

titleTextColor: UIColor -> Sets title's text color

messageTextColor: UIColor -> Sets message's text color

titleFont: UIFont -> Sets title's font

messageFont: UIFont -> Sets message's font

isHeaderIconFilled: Bool -> Chooses filled icons instead of outline ones. Default is false.

alertBackgroundColor: UIColor -> Sets popup's background color.

popupWidth: CGFloat -> Width of the popup view

hasRoundedCorners: Bool -> Apply rounded corners to alert view. Default is true.

hasShadow: Bool -> Apply shadows around the popup. Defualt is true.

circleFillColor: UIColor -> Sets background color of header icon. (Color of circle area)

isActionButtonsVertical: Bool -> Alignes action buttons vertical. Default is false. Maximum number of horizontal buttons is 3.

canHideWhenTapBack -> Hide self when tapped backgroundView. Default is false.

hideAnimationDuration: TimeInterval -> Sets the animation duration of hide animation

hideAnimations: CDAlertAnimationBlock -> Sets the hiding animations depending on the center, transform and alpha values. You can create your animations by changing these values for alert popup.

If you enabled text field with setting isTextFieldHidden property to false, following properties will be available also:

textFieldFont: UIFont -> Font of textField's text

textFieldIsSecureTextEntry: Bool -> Sets the isSecureTextEntry property of UITextField

textFieldReturnKeyType: UIReturnKeyType -> Sets the returnKeyType property of UITextField

textFieldTextAlignment: NSTextAlignment -> Sets the textAlignment property of UITextField. Default is .left.

textFieldPlaceholderText: String? -> Sets the placeholder text for UITextField.

textFieldAutocapitalizationType: UITextAutocapitalizationType -> Sets the autocapitalizationType property of UITextField. Default is .none.

textFieldBackgroundColor: UIColor -> Sets UITextField's background color.

textFieldTintColor: UIColor -> Sets UITextField's tint color.

textFieldText: String? -> Sets & gets UITextField's text.

textFieldHeight: CGFloat -> Sets the height of UITextField.

textFieldDelegate: UITextViewDelegate? -> Sets the delegate of UITextField. Default delegate is CDAlertView. If you overwrite this, you're responsible for resigning the UITextField.

autoHideTime: TimeInterval? -> Sets the time interval for dismiss time. Default is nil.

Advanced action initialization:

font, textColor, backgroundColor, handler are all optional and has default parameter values. You can initilize with them or set them after initialization.

let action = CDAlertViewAction(title: "Action Title", font: UIFont.yourCustomFont, textColor: UIColor.yourTextColor, backgroundColor: UIColor.yourBackgroundColor, handler: { action in })
alertView.addAction(action)

NOTE: Aligning buttons vertical and horizontal is possible. But using more than 3 buttons in horizontal placement is not possible.

List of CDAlertViewAction Options

buttonTitle: String -> Set's the action button title

buttonTextColor: UIColor -> Sets the action button title color. Default value is RGB(27,169,225).

buttonFont: UIFont -> Sets the action button title font. Default value is UIFont.systemFont(ofSize: 17).

buttonBackgroundColor: UIColor -> Sets the background color of action button. If not set, it uses alertBackgroundColor of CDAlertView.

List of available methods

textFieldBecomeFirstResponder() -> Calls the becomeFirstResponder() method of textField if alert.isTextFieldHidden set to true. Otherwise, does nothing.

textFieldResignFirstResponder() -> Calls the resignFirstResponder() method of textField if alert.isTextFieldHidden set to true. Otherwise, does nothing.

Example

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

Installation

This library supports Swift 5. Use 0.9.1 for Swift 4.2. Use 0.6.1 for Swift 3.1.

Using CocoaPods

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

pod "CDAlertView"

Using Carthage

CDAlertView is available through Carthage. To install it, simply add the following line to your Cartfile:

github "candostdagdeviren/CDAlertView"

Requirements

  • Xcode 9
  • Swift 4
  • iOS 9.0+

Icons

Thanks to Icons8 for beautiful icons.

License

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

cdalertview's People

Contributors

candostdagdeviren avatar mlchild avatar rstewart22 avatar yigitcanyurtsever avatar ykeisuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cdalertview's Issues

image icon doesn't work

Hi, first of all thank you for your job, i think it's very nice.
About my problem:
i don't like use cocoapods so i have imported CdAlertView manually but when i call the alert view the image in the center doesn't work. this is a sample
schermata 2018-05-22 alle 10 04 14

CDAlertView play nice with IQKeyboardManager?

Hello,

I'm trying to get the IQKeyboardManager plugin (https://github.com/hackiftekhar/IQKeyboardManager) to play nicely with your great CDAlertView plugin... when the keyboard pops up, I was hoping that the AlertView popup would shift up alittle to provide viewing capability of the textfield although there is some odd behaviour.

When I first click on the textfield:
screen1

When I click on the textfield for the second time, the popup moves to the top:
screen2

Is it possible to move the popup just a tad higher then original position and on the first textfield click?

Thanks

more than one textField

Can i add more than one text field to the alert view. Will you support actionSheets in the future

Many method are not available to used in Objective-C.

Hi,

I try to use CDAlertView in a Obj-C project but I've noticed some methods are not available. For exemple hide(animations: CDAlertAnimationBlock? = nil, isPopupAnimated: Bool) is not here.

I've install the library with CocoaPods.

To try, I've created a new method in CDAlertView :

public func hide(isPopupAnimated: Bool) { self.hide(animations: nil, isPopupAnimated: isPopupAnimated) }

This one appear in the generated .h. It seem like the CDAlertAnimationBlock is the problem.

Swift 5

Hello, I don't know if anyone is still maintaining this useful project.
If there is, can you please help convert this project to the latest swift version.

Use without Shared Window

What is the best way to implement this without using the shared window code?

UIApplication.shared.keyWindow?.addSubview(self)

No icon bug

Hello,
I really like your library and using it :)
When I use it as .notification type, its background comes with blue but its icon does not appear. Here is the image from the bug.
I simply use it from your USAGE part.

whatsapp image 2017-08-01 at 6 12 22 pm

Add ability to hide top circle

I'd like the ability to easily hide the top circle and just have a standard alert where I can control the font sizes.

anyways to blur

Are there anyways to add blur to the background. of the alert.

Message in alert is getting truncated

In my app presenting an alert but the message getting truncated to one line

let alert = CDAlertView(title: title, message: message, type: CDAlertViewType.error)
let okay = CDAlertViewAction(title: "OK", font: nil, textColor: nil, backgroundColor: nil) { (action) in
}
alert.add(action: okay)
alert.show()

screen shot 2017-11-06 at 9 16 06 pm

Android Package?

Is there an Android repo I could leverage? I love this package and want to implement it in the Android version of my app!

Keyboard Notification

Hey guys, just wanted to see if this was a bug or my usage was incorrect - is the AlertView supposed to adjust its frame in the event of a keyboard show notification like a UIAlertController? As soon as the keyboard comes up (I have isTextFieldHidden set to false), it covers the bottom of the alert (+ button). Thanks!

Handle action on tap

It isn't very clear in the documentation on how to handle different actions with a completion handler. Can someone please let me know how I can detect whether my "done action" or "cancel action" buttons are hit? Code is below. Thanks!

`let alert = CDAlertView(title: "Deleting All Accounts", message: "Are you sure you wish to delete all accounts?", type: .warning)

let doneAction = CDAlertViewAction(title: "Sure! πŸ’ͺ")
alert.add(action: doneAction)
let nevermindAction = CDAlertViewAction(title: "Nevermind 😬")
alert.add(action: nevermindAction)
alert.show()`

Layout issue because of LayoutConstraintsExtension

LayoutConstraintsExtension causes Layout issues when you use your library with some other libraries. I found this problem with CLImageEditor. The reason in the specific case, is that CLImageEditor uses, in its own extension, the same function names: setHeight, setWidth. To solve the problem, I changed the name of these functions in setHeightCD, setWidthCD. Please could you change the names of all the functions in the LayoutConstraintsExtension with some suffix such as CD?

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.