RDMBorderedButton 1.1.0

RDMBorderedButton 1.1.0

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2017年4月

Reese McLean 维护。




#RDMBorderedButton

按钮的子类,添加了边框。

RDMBorderedButton Screenshot

##用法

在代码中:使用 initWithFrame 创建一个按钮并将其添加到子视图中。

Interface Builder:添加一个按钮,通常设置类为 RDMBorderedButton — 由于 iOS 7.1 的一些错误,需要您在 Interface Builder 中将按钮类型设置为 Custom。所有属性都可以使用属性检查器进行调整。示例项目显示了黑色和黄色按钮的这种方法。

###圆角半径

默认情况下,RDMBorderedButton 将根据其框架调整其边框的圆角半径。您可以通过以下方式关闭此功能

button.adjustsCornerRadiusBasedOnFrame = NO; //Default is YES

您还可以更改此自动调整的圆角半径的比率

button.cornerRadiusRatioToSmallestSide = 1.0/4.0; //Default is 1.0/6.0

请注意,对圆角半径的更改不会动画化。如果您希望圆角半径的更改是动画化的,您将需要使用 CoreAnimation 动画化 key path。请参阅示例项目中的程序性视图控制器以查看此示例。

您可以通过手动方式调整圆角半径(这将关闭自动调整)

//This will forward the cornerRadius to the button's layer and turn off automatic adjustments
button.cornerRadius = 6.0;

###边框宽度

可以程序化地调整按钮的边框宽度

button.borderWidth = 2.0;

###颜色

文本和边框颜色一起进行调整。对于正常状态,它们可以使用以下任何一种进行更改

button.tintColor = [UIColor greenColor];

[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; 

禁用状态可以使用以下方式调整

[button setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled]; //Default is [UIColor grayColor]

高亮时的文本颜色应使用以下方式更改

[self setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted]; //Default is [UIColor whiteColor]