ALButton 0.0.1

ALButton 0.0.1

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最后发布2015年2月
SPM支持 SPM

Alex Leite 维护.



ALButton 0.0.1

  • 作者:
  • Alex Leite

关于

这个控件是 Apple 默认 UIButton 的子类。它增加了一些功能,减少了自定义 UIButton 的外观和行为的代码行数,并利用了一些 Swift 的优点。

如何安装?

将控件集成到项目中的最简单方法是将 ALButton.swift 文件复制到您的项目中。

如何使用

初始化

初始化按钮有三种方式

//- 1. Full Initialization

let style = ALButton.ButtonStyle()
//-- set style

let myButton = ALButton(title: "Button Title", style: style, touchUpInsideHandler: {
    (sender ) in

    //-- Implement touch up inside event here
})

//- 2. Simple initialization with style:

var style = ALButton.ButtonStyle()
//-- set style

let myButton = ALButton(title: "Button Title", style: style)

//- 3. Short initialization

let myButton = ALButton(title: "Button Title")

您还可以使用尾部闭包更方便地初始化按钮

//- Short Initialization

let myButton = ALButton(title: "Button Title") {
    sender in

    //-- Implement touch up inside event here
}

//- Full Initialization

let myButton = ALButton(title: "Button Title", style: style) {
    sender in

    //- Implement touch up inside code here
}

添加 Touch Up Inside 处理程序

在初始化按钮时,您可以选择不添加 Touch Up Inside 处理程序。您可以使用以下代码在任何点添加处理程序

myButton.touchUpInside {
    sender in

    //-- Implement touch up inside code here
}

应用样式

要为按钮应用样式,您应该使用 ButtonStyle 结构。通过它,您可以设置以下属性:titleFonttitleColordisabledTitleColorbackgroundColorhighlightColordisabledColor

您可以选择在初始化时或之后通过设置按钮的 style 属性来传递此样式。

许可证

此组件在 MIT 许可证下可用