iOS拓展36-分类分享

2018-02-23  本文已影响29人  Abler

最近对项目进行优化,封装了两个常用的分类,给大家分享一下 demo的使用

1.UIButton的分类,主要调整图片位置,
typedef NS_ENUM(NSUInteger, SYImageAlignment) {
    SYImageAlignmentTop = 0, // 图片在上
    SYImageAlignmentLeft, //图片在左,默认,space增加间距
    SYImageAlignmentRight, // 图片在右
    SYImageAlignmentBottom, // 图片在下
};
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 150, 80)];
    [button setImage:[UIImage imageNamed:@"clock"] forState:UIControlStateNormal];
    [button setTitle:@"我在下面" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor greenColor];
    [button changeButtonImageAlignment:SYImageAlignmentTop withSpace:10.0];// 设置好图片和文字之后调用该方法
    [self.view addSubview:button];
UIButton的分类.png
2.UIAlertController分类,方便创建取消和确定弹框
/// 包含红色取消
+ (instancetype)alertControllerWithTitle:(NSString *)title
                                 message:(NSString *)message
                          preferredStyle:(UIAlertControllerStyle)preferredStyle
                              sureHandle:(void(^)(UIAlertAction *action))sureHandle;
/// 只有确定按钮
+ (instancetype)alertControllerWithTitle:(NSString *)title
                                 message:(NSString *)message
                          preferredStyle:(UIAlertControllerStyle)preferredStyle
                          onlySureHandle:(void(^)(UIAlertAction *action))sureHandle;
/**
 自定义确定和取消
 
 @param title title
 @param message message
 @param preferredStyle alertController样式
 @param sureTitle 右侧文字
 @param sureActionStyle 右侧样式
 @param sureHandle 右侧方法回调
 @param cancelTitle 左侧文字
 @param cancelActionStyle 左侧样式
 @param cancelHandle 左侧方法回调
 @return alertController
 */
+ (instancetype)alertControllerWithTitle:(NSString *)title
                                 message:(NSString *)message
                          preferredStyle:(UIAlertControllerStyle)preferredStyle
                               sureTitle:(NSString *)sureTitle
                         sureActionStyle:(UIAlertActionStyle)sureActionStyle
                              sureHandle:(void(^)(UIAlertAction *action))sureHandle
                             cancelTitle:(NSString *)cancelTitle
                       cancelActionStyle:(UIAlertActionStyle)cancelActionStyle
                            cancelHandle:(void(^)(UIAlertAction *action))cancelHandle;
UIAlertController分类
上一篇下一篇

猜你喜欢

热点阅读