登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

CDAlertView:使用简洁、可定制 Alert 组件 [复制链接]

2016-11-16 21:15
李世铿 阅读:497 评论:0 赞:2
Tag:  alertViewCDAlertViewSwift

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

Screenshots

Animations

  

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! :muscle:")
alert.add(action: doneAction)
let nevermindAction = CDAlertViewAction(title: "Nevermind :expressionless:")
alert.add(action: nevermindAction)
alert.show()

CDAlertView types:

public enum CDAlertViewType {
    case error, warning, success, notification, alarm, empty
}

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

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

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.

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.

Example

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

Installation

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

pod "CDAlertView"

Requirements

  • Xcode 8
  • iOS 9.0+

Author

Candost Dagdeviren, candostdagdeviren@gmail.com

Icons

Thanks to Icons8 for beautiful icons.

License

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


分享到:
我来说两句
您需要登录后才可以评论 登录 | 立即注册
所有评论(0)
关闭

每日头条

通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

返回顶部