@property (nonatomic,copy,readonly) XJButton * (^setSeletedTitle) (NSString * text);
@property (nonatomic,copy,readonly) XJButton * (^setTitle) (NSString * text);
@property(nonatomic,copy,readonly) XJButton *(^setSeletedImage)(UIImage *image);
@property(nonatomic,copy,readonly) XJButton *(^setImage)(UIImage *image);
@property(nonatomic,copy,readonly) XJButton *(^setAction)(void(^)(XJButton *button));
@property(nonatomic,copy,readonly) XJButton *(^setFont)(UIFont *font);
@property(nonatomic,copy,readonly) XJButton *(^setTextColor)(UIColor *color);
@property(nonatomic,copy,readonly) XJButton *(^setBgColor)(UIColor *color);
@property(nonatomic,copy,readonly) XJButton *(^setImagePosition)(XJButtonImagePosition imagePosition);
@property(nonatomic,copy,readonly) XJButton *(^setSpacingBetweenImageAndTitle)(CGFloat spacingBetweenImageAndTitle);
@property(nonatomic,copy,readonly) XJButton *(^setCornerRadius)(CGFloat cornerRadius);
@property(nonatomic,copy,readonly) XJButton *(^setTheSameAppearanceAsButton)(UIButton *button);
@property(nonatomic,copy,readonly) XJButton *(^setContentEdgeInsets)(UIEdgeInsets edgeInsets);
@property(nonatomic,copy,readonly) XJButton *(^setExpandClickArea)(UIEdgeInsets expandClickArea);
设置某一个位置的圆角 优先级要高于 cornerRadius; 默认半圆, 可根据 oneOrMorecornerRadius == -1 则是半圆 与 cornerRadius 属性互斥 ,调用者只需要调用一个即可
@property(nonatomic,copy,readonly) XJButton *(^setOneOrMoreCorner)(UIRectCorner corner,CGFloat oneOrMorecornerRadius);
@property(nonatomic,copy,readonly) XJButton *(^setGradation)(NSArray <UIColor *> *colors,XJButtonGradientType type);
@property(nonatomic,copy,readonly) XJButton *(^setAttributedString)(NSMutableAttributedString *attributedString);
let button = XJButton(); button.setFont(.SPMFont(fontSize: 14)) .setCornerRadius(-1) .setTextColor(.white) .setBgColor(.appRedColor) .setContentEdgeInsets(UIEdgeInsets(top: 8, left: 35, bottom: 8, right: 35)).sizeToFit()
target 'testaaaa' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'XJEasyButton', '0.1.3'
end
如果是swift 的话 ,可以为这个Button 写一个扩展 ,调用更加方便。例如
/// 创建一个button
/// - Parameters:
/// - size: 文字大小
/// - type: 文字类型
/// - textColorHex: 文字颜色
/// - alpha: 透明度
/// - title: 标题
/// - imageName: 图片名称
/// - postion: 布局类型
/// - spacing: 间距
convenience init(size: Int? = 14, type: MCFontCategory.typeface? = .Regular, textColorHex: String? = nil, alpha: CGFloat = 1.0, title:String? = nil, imageName:String? = nil, postion : XJButtonImagePosition? = nil,spacing:CGFloat = 1, seletedImage:String? = nil,clickAction:((XJButton)->())? = nil) {
self.init(type: .custom);
if let textColorHex = textColorHex {
_ = self.setTextColor(UIColor(hexString: textColorHex,alpha));
}
if let postion = postion {
_ = self.setImagePosition(postion).setSpacingBetweenImageAndTitle(spacing);
}
if let size = size , let type = type {
_ = self.setFont(MCFontPF(size, type));
}
if let title = title {
_ = self.setTitle(title);
}
if let imageName = imageName {
_ = self.setImage(UIImage(named: imageName) ?? UIImage())
}
if let seletedImage = seletedImage {
_ = self.setSeletedImage(UIImage(named: seletedImage) ?? UIImage())
}
if let clickAction = clickAction{
_ = self.setAction(clickAction);
}
self.translatesAutoresizingMaskIntoConstraints = false;
}