美文网首页iOS开发攻城狮的集散地手机移动程序开发
【原创】一个可调整图片位置的UIButton

【原创】一个可调整图片位置的UIButton

作者: 时间之名 | 来源:发表于2017-01-07 16:14 被阅读0次

CSButton - Github

Custom the position of the ImageView relative to the titleLabel in UIButton.

一个UIButon的派生类,可以调整图片与文字相对位置,图片和文字间距,以及图片显示大小。

效果图

CSButton

接入

  • 方式一:Cocoapods导入

pod 'CSButton'

  • 方式二:直接将下面文件添加(拖入)项目中
CSButton.h
CSButton.m

功能

1、 调整图片与文字相对位置,
配置cs_buttonImagePositionType属性即可。

@property (nonatomic, assign) CSButtonImagePositionType cs_buttonImagePositionType;

该属性为枚举类型:

typedef NS_ENUM(NSInteger, CSButtonImagePositionType) {
    CSButtonImagePositionTypeDefault,
    CSButtonImagePositionTypeRight, 
    CSButtonImagePositionTypeTop, 
    CSButtonImagePositionTypeBottom 
};

2、 调整图片与文字间的距离,
配置cs_middleDistance属性即可。

@property (nonatomic, assign) CGFloat cs_middleDistance;

3、 调整图片展示大小,
配置cs_imageViewSize属性即可。

@property (nonatomic, assign) CGSize cs_imageViewSize;

说明

  1. 文字和图片都遵循水平竖直居中。
  2. 默认关闭了点击时图片高亮效果。如果需要开启则设置adjustsImageWhenHighlightedYES

Clone

git clone --recursive https://github.com/chenaiwubu/CSButton.git

Github连接:https://github.com/chenaiwubu/CSButton

相关文章

网友评论

    本文标题:【原创】一个可调整图片位置的UIButton

    本文链接:https://www.haomeiwen.com/subject/niyfbttx.html