# DGButton **Repository Path**: xuyihan2004/DGButton ## Basic Information - **Project Name**: DGButton - **Description**: 自定义按钮 - **Primary Language**: Objective-C - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-04-23 - **Last Updated**: 2023-04-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DGButton #### 介绍 **iOS 自定义按钮**。默认的button局限性太大,很难改变图文的位置。这里重新封装了一个button,支持设置图片与标题的不同布局方式,与排列形式,具体在下面的使用说明中会介绍到。增加了角标与等待动画,并且灵活支持xib、storyboard编译绘制。,基本可以满足当前大多数APP的使用。 ![介绍图1](https://images.gitee.com/uploads/images/2019/0113/180008_6eaf7b3c_1845415.png "屏幕截图.png") ![介绍图2](https://images.gitee.com/uploads/images/2019/0113/175918_b5f5b061_1845415.png "屏幕截图.png") #### 安装教程 1、手动添加 直接将DGButtonSDK文件夹拖入工程,#import "DGButton" 即可使用 2、cocoapods添加 Podfile中 添加 pod 'DGButton', '~> 2.2.2' 。 然后 command 更新 pod install. _ 【切记】如果需要xib使用,请在Podfile的target..end块中添加如下代码,否则可能会出现“IB Designables Failed to render and update auto layout status : dlopen(Cosmos.framework, 1): no suitable image found”错误信息。_ ``` platform :ios, ‘8.0’ use_frameworks! pod 'DGButton', '~> 2.2.2' target 'xxxx' do post_install do |installer installer.pods_project.build_configurations.each do |config config.build_settings.delete('CODE_SIGNING_ALLOWED') config.build_settings.delete('CODE_SIGNING_REQUIRED') end end end ``` #### 使用说明 1. code创建 ``` //code create DGButton DGButton * button1 = [DGButton buttonArrangeType:DGButtonArrangeTypeTitleInFrontOfTheImage]; //初始化风格,默认为DGButtonArrangeTypeTitleInFrontOfTheImage button1.imageSize = CGSizeMake(20, 20); //设置图片大小,不设置将会自动适应图片大小。 button1.alignmentType = DGButtonAlignmentTypeLeft|DGButtonAlignmentTypeCenter; //对齐方式 button1.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10); // 内容间距 [button1 setCornerCount:2 type:DGButtonCornerMarkTypePoint]; // 设置角标 button1.frame = CGRectMake(20, 20, 100, 40); button1.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2]; [button1 setImage:[UIImage imageNamed:@"6"] forState:UIControlStateNormal]; [button1 setTitle:@"自定义Button" forState:UIControlStateNormal]; [button1 addTarget:self action:@selector(btn1Action:) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:button1]; ``` 2. xib拖拽 2.1 拖入一个UIView,将类名改为 DGButton ![图片1](https://images.gitee.com/uploads/images/2019/0111/162500_1bf2e0c8_1845415.png "屏幕截图.png") 2.2 修改属性 ![图片2](https://images.gitee.com/uploads/images/2019/0111/162850_d6e13e05_1845415.png "屏幕截图.png") ps:xib支持修改的属性 属性名 | 描述 ------------- | ------------- imageSize | 按钮图片大小(默认为自适应) image | 图片 title | 标题 fontSize| 字体大小 titleColor|标题颜色(默认状态) cornerRadius|按钮圆角半径 borderWidth |按钮边框宽度 borderColor |边框颜色 type |排列类型(一共4种:图片在前,图片在后,图片在上,图片在下) alignCenter |是否居中对齐 alignTop |是否上对齐 alignLeft |是否左对齐 alignBottom |是否下对齐 alignRight |是否有对齐 2.3 效果展示 ![图片3](https://images.gitee.com/uploads/images/2019/0113/151630_ab1b5145_1845415.png "屏幕截图.png")