Y_ImageTitleButton 0.0.2

Y_ImageTitleButton 0.0.2

Hello_World 维护。




  • 作者:
  • 1ilI

Y_ImgTitlButton

封装 UIButton,快速创建一个带有图片和标题的按钮。

功能

以前定义一个带有图片和标题的按钮,如果要按照自己的方式排布,不免要使用 contentVerticalAlignment、contentHorizontalAlignment、imageEdgeInsets、titleEdgeInsets 等属性。

现在通过自定义按钮类型(如图下文字、左图右文字等),可以轻松创建带有图片和标题的按钮,使用起来更加方便。

定义的枚举类型如下:

typedef enum {
    ImageTopTitleBottom,        //图上字下
    TitleTopImageBottom,        //图下字上
    ImageLeftTitleRight,        //图左字右
    TitleLeftImageRight,        //图右字左
    
    ImageLeftTitleRightLeft,    //图左字右 字靠右
    ImageLeftTitleRightCenter,  //图左字右 字居中
    
    TitleLeftImageRightCenter,  //图右字左 字居中
    TitleLeftImageRightLeft,    //图右字左 图靠左
    
    FitTitleLeftImageRight,     //图右字左适应
}ButtonStyle;

使用

  • 普通使用
//创建一个图上字下的按钮
Y_ImgTitlButton *button = [[Y_ImgTitlButton alloc] initWithStyle:ImageTopTitleBottom];
  • 带margin的按钮
//设置按钮的 margin
Y_ImgTitlButton *button = [[Y_ImgTitlButton alloc] initWithStyle:ImageTopTitleBottom margin:UIEdgeInsetsMake(10, 20, 30, 40)];
  • 带margin和padding的按钮
//设置按钮的 margin
Y_ImgTitlButton *button = [[Y_ImgTitlButton alloc] initWithStyle:ImageLeftTitleRight margin:UIEdgeInsetsMake(0, 0, 0, 0) padding:CGSizeMake(20, 2333)];

示例

show

详细使用请参考示例