Custom alert View to iOS applications

Overview

Platform License Version

A simple, easy and custom iOS UIAlertView written in Swift

Malert came to facilitates custom alert views as UIAlertController. Malert allows you to personalize your alertView so that it matches your application layout

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

Requirements

  • Xcode 10.0+
  • Swift 5.0+

Versioning

  • Swift 3.x: 1.1.5
  • Swift 4.0: 2.0~3.0
  • Swift 4.2: 3.1*
  • Swift 5: 4.0

Installation

Pod

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

pod 'Malert'

Manually

If you don't use any dependency managers, you can integrate Malert in your project manually just adding the files which contains Malert Classes.

Congratulations!!! You can run Malert without any dependency managers!

Example

This is a simple example. If you want to know more, check the app Example cause There are more than 10 customizated Malerts.

Malert with custom view

import Malert

...

let view = ExampleView.instantiateFromNib()
let malert = Malert(customView: view)

let action = MalertAction(title: "OK")
action.tintColor = UIColor(red:0.15, green:0.64, blue:0.85, alpha:1.0)

malert.addAction(action)

present(malert, animated: true)

How to create actions

To add buttons to your malert There is a function called addAction that you need to provide a MalertAction object to build customizable buttons.

let malert = ... 
   	 
let action = MalertAction(title: "Take the tour") {
   print("Closure called when action was clicked")
}

action.cornerRadius = 8
action.tintColor = .white
action.backgroundColor = UIColor(red:0.38, green:0.76, blue:0.15, alpha:1.0)

malert.addAction(action)
	
...

For more details check the examples

Customize

Malert provides some attributes to cutomize it:

/* Animation attr */
public var presentDuration: TimeInterval
public var dismissDuration: TimeInterval
public var animationType: MalertAnimationType

/* Container attr */
public var margin: CGFloat
public var cornerRadius: CGFloat
public var backgroundColor: UIColor?

/* Title attr */
public var titleFont: UIFont
public var textColor: UIColor
public var textAlign: NSTextAlignment

/* Buttons attr */
public var buttonsHeight: CGFloat
public var separetorColor: UIColor
public var buttonsSpace: CGFloat
public var buttonsSideMargin: CGFloat
public var buttonsBottomMargin: CGFloat
public var buttonsAxis: UILayoutConstraintAxis

It is very simple how you can do that. Just change malert's attributes before present it:

let exampleView = ExampleView()

let alert = Malert(customView: exampleView)

//customizing your malert

alert.animationType = .modalRight
alert.buttonsSideMargin = 60
alert.buttonsBottomMargin = 16
alert.buttonsAxis = .horizontal
alert.separetorColor = .clear

Customize actions

Malert enable some attributes to customize each action:

public var tintColor: UIColor
public var backgroundColor: UIColor
public var cornerRadius: CGFloat
public var borderColor: UIColor
public var borderWidth: CGFloat

If you need more attributes to customize it, please let us know, create an issue or a pull request.

Contributing

If you think that we can do the Malert more powerful please contribute with this project. And let's improve it to help other developers.

Create a pull request or let's talk about something in issues. Thanks a lot.

Author

Vitor Mesquita, [email protected]

License

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

Comments
  • fixed Malert view having invalid height due to orientation issue

    fixed Malert view having invalid height due to orientation issue

    Dear @vitormesquita,

    Following this issue, it looks like it will be sufficient to add the following condition to the if statement in order to fix the problem:

    if UIDevice.current.orientation.isLandscape && !preferredInterfaceOrientationForPresentation.isPortrait {
        ...
    }
    

    According to Apple documentation for preferredInterfaceOrientationForPresentation.isPortrait: A Boolean value indicating whether the user interface is currently presented in a portrait orientation.

    You're very welcome to check other branch I created to showcase the issue and the fix (also added examples to test it.) All the examples are already configured for you.

    Way to replicate the issue:

    1. Clone my Malert fork from orientation-fix-test branch
    2. Run the Malert Example application
    3. Rotate the device to Landscape
    4. While in landscape orientation, click on "Example Orientation Issue" example
    5. While in landscape orientation, click on "Example Orientation Issue (fixed)" to showcase the fix

    I've also done some tests to determine whether this affects users using the application in Landscape mode by adding the landscape orientation in info.plist

    Tested on:

    • IPhone 8 (physical device)
    • IPhone 12 Pro Max (simulator)
    • IPad (simulator)

    Kindly let me know if you have any questions or concerns. If you think there might be a better solution for this issue I'm very open to discuss it.

    Thank You!

    P.S. I forgot to remove the Landscape orientation from Info.plist on orientation-fix-test branch so please remove it before testing the issue.

    opened by bwmhamad 3
  • Added overlay color config, renamed 'round' method, fixed deprecated protocol inheritance

    Added overlay color config, renamed 'round' method, fixed deprecated protocol inheritance

    Added overlay color configuration

    You can now set the color of overlay on Malert object through overlayColor property. Color is then set on background color of visibleView. This can be useful for some use cases like when it's required by the design.

    Renamed round method of UIView extension to roundView

    I've renamed 'round' method of UIView extension since it hides Swift default 'round' method and creates issues when working with classes extending UIView. Although I couldn't find where this method is used. Kindly check if I'm missing something.

    MalertActionCallbackProtocol now extends AnyObject

    According to Apple deprecation and requirement.

    opened by bwmhamad 2
  • Incorrect height of custom view

    Incorrect height of custom view

    Hello,

    There's an issue with custom view height when application "Supported interface orientations" is set to portrait but the device is in landscape orientation.

    Looks like the issue is following code block of Malert constrains extension (Malert+Constraints.swift):

    if UIDevice.current.orientation.isLandscape {
             let topContraint = malertView.topAnchor.constraint(equalTo: visibleView.topAnchor, constant: 16)
             topContraint.priority = UILayoutPriority(900)
             malertConstraints.append(topContraint)
    
             let bottomConstraint = malertView.bottomAnchor.constraint(equalTo: visibleView.bottomAnchor, constant: -16)
             bottomConstraint.priority = UILayoutPriority(900)
             malertConstraints.append(bottomConstraint)
    }
    

    Above if condition doesn't sufficiently checks if landscape orientation is enabled for the application. I suggest to change above condition statement to:

    if UIDevice.current.orientation.isLandscape && supportedInterfaceOrientations.contains(.landscape) {
        ...
    }
    

    This way the issue can be avoided by following extension:

    extension Malert {
    	public override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    		return .portrait
    	}
    }
    

    Kindly note that this is just something I came up with on the fly to patch this issue so please feel free to implement a better solution if necessary.

    Thank you!

    opened by bwmhamad 2
  • Manual Installation

    Manual Installation

    CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

    It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

    opened by lfarah 1
  • Issue in landscape mode

    Issue in landscape mode

    I have a following issue when my app goes to landscape mode. Do you have any suggestions?

    IMG_006A143B68F9-1

    I would like alert to be a fixed width instead of going almost entire width of the screen. Thanks

    opened by nemanja-nisic 3
Releases(4.2)
  • 4.2(Jul 13, 2021)

    Implemented enhancements

    • Add overlayColor attribute on Malert to change the background color
    • Renamed round method to roundCorners
    • Remove coder init from Malert
    Source code(tar.gz)
    Source code(zip)
  • 4.0(Oct 23, 2019)

  • 3.1.4(Oct 23, 2019)

    Implemented enhancements

    • Added method onDismissMalert on Malert to be called when dismiss viewController's function called completion block
    • Removing some prints
    • Put #if DEBUG to print dealloc
    Source code(tar.gz)
    Source code(zip)
  • 3.1.3(Oct 23, 2019)

    Implemented enhancements

    • Removed font attribute from MalertAction
    • Added buttonsFont attribute on Malert to represents all Alert button's font
    Source code(tar.gz)
    Source code(zip)
  • 3.1.2(Oct 23, 2019)

  • 3.1(Oct 23, 2019)

  • 3.0(Jul 27, 2018)

    Implemented enhancements:

    • Refactoring the way how to create an Malert to be more similar with UIAlertController
    • Changing MalertViewController -> Malert to be presented as UIViewController
    • Changing MalertButtonStruct -> MalertAction
    • Removing MalertViewConfiguration, MalertButtonConfiguration
    • Removing shared instance and all queue manager from Malert
    • Add new attributes to be more customizable and flexible
    • Removing Cartography
    • Add dismissOnActionTapped to dismiss when a call to action was clicked
    Source code(tar.gz)
    Source code(zip)
  • 2.0(Nov 21, 2017)

  • 1.1.5(Feb 6, 2018)

  • 1.1.4(Feb 6, 2018)

  • 1.1.3(Feb 6, 2018)

  • 1.1.2(Feb 6, 2018)

  • 1.1.1(Feb 6, 2018)

  • 1.1(Feb 6, 2018)

  • 1.0(Feb 6, 2018)

    Implemented enhancements:

    • Change MalertManager -> Malert
    • Undocking Malert from UIWindow, and makes create malert only with other UIViewController
    • Create custom dismissed from Malert according to MalertAnimationType
    • Added tapToDismiss attribute to close MalertView when clicked

    Fixed bugs:

    • Tap on View and Dismiss current MalertView #3
    • Error to hide keyboard when clicked on view #4
    Source code(tar.gz)
    Source code(zip)
Owner
Vitor Mesquita
Senior iOS Developer
Vitor Mesquita
Highly configurable iOS Alert Views with custom content views

NYAlertViewController NYAlertViewController is a replacement for UIAlertController/UIAlertView with support for content views and UI customization. Fe

Nealon Young 609 Nov 20, 2022
A colored alert view for your iOS.

日本語 KRAlertController KRAlertController is a beautiful and easy-to-use alert controller for your iOS written by Swift. Requirements iOS 10.0+ Xcode 10

K.R.Impedance 52 Jun 30, 2022
Live animated Alert View for iOS written in Swift

Sweet Alert iOS Beautiful Animated custom Alert View inspired from javascript library SweetAlert. Written in Swift this SweetAlertView can be used in

Sahil 2k Dec 22, 2022
Simple DropDown Alert View For Any iOS Projects.

⚠️ DEPRECATED, NO LONGER MAINTAINED JDropDownAlert JDropDownALert Simple DropDown Alert View For Any iOS Projects. Usage Top let alert = JDropDown

WonJo 71 Jul 17, 2022
Beautiful animated Alert View. Written in Swift

SCLAlertView Animated Alert View written in Swift, which can be used as a UIAlertView or UIAlertController replacement. Since UIAlertView is deprecate

Viktor Radchenko 5.2k Jan 3, 2023
Simple Alert View written in Swift, which can be used as a UIAlertController. (AlertController/AlertView/ActionSheet)

DOAlertController Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and ea

Daiki Okumura 406 Sep 5, 2022
Beautiful animated Login Alert View. Written in Objective-C

UIAlertView - Objective-C Animated Login Alert View written in Swift but ported to Objective-C, which can be used as a UIAlertView or UIAlertControlle

Letovsky 2 Dec 22, 2021
JAlert - This is "Alert View" project for UIKit + SwiftUI. you can use easily

JAlert Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation JAlert is a

Jackson 3 Feb 22, 2022
AlertTransition is a extensible library for making view controller transitions, especially for alert transitions.

AlertTransition AlertTransition is a extensible library for making view controller transitions, especially for alert transitions. Overview AlertTransi

Loopeer 570 Nov 29, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
A Swift package for iOS/tvOS for easy alert presentation

AlertPresenter Listed on the Swift Package Index and originally posted on my blog. It can be fiddly to handle the presentation of alerts on a specific

Chris Mash 14 Jul 1, 2022
TextFieldAlert - A SwiftUI alert with text field(s) for iOS 13 and greater.

TextFieldAlert A SwiftUI alert with text field(s) for iOS 13 and greater. As Apple is going to introduce text field(s) as an alert actions in iOS 16,

Piotr Sochalewski 13 Dec 5, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Masahiro Watanabe 97 Nov 11, 2022
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController. Screenshots Animations Usage Basic usage witho

Candost Dagdeviren 1.1k Dec 30, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.

SPAlert Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's

Ivan Vorobei 1.8k Jan 7, 2023
Zingle – An alert will display underneath your UINavigationBar 🎅

Zingle Zingle – An alert will display underneath your UINavigationBar ?? ?? Note: Zingle has a dependency to have a UINavigationController in your app

Hemang 109 Jun 24, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
Animated alert library like Swarm app.

TKSwarmAlert Animation Tool for Alert like Swarm app. ScreenShot Installation CocoaPods You can use CocoaPods to install TKSwarmAlert by adding it to

Takuya Okamoto 581 Dec 2, 2022