Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议所有配置都可以一次性设置而不是每个实例都配置一遍。 #29

Closed
seekcx opened this issue Nov 28, 2016 · 6 comments

Comments

@seekcx
Copy link

seekcx commented Nov 28, 2016

类似SVProgressHUD。

大多数项目为了达到视觉一致,都会统一进行设置的。

但是目前这样,每个实例设置一遍不仅冗余代码多,而且难以维护。

另:建议增加title contentInset设置,类似微信目前的title比较高,留白较多,看起来会更加大气。

@iTofu
Copy link
Owner

iTofu commented Nov 28, 2016

是的,谢谢你的反馈,这是一个可改进点。

关于统一配置,我之前考虑过这个问题,想法如下,你可以帮我一块看看是否满足需求:

增加一个 Config 类,它提供一个单例,用来统一配置参数。LCActionSheet 提供一个 -initWithConfig: 方法,在初始化时用该方法取代 -init: 方法,并传入 Config 单例,这样在初始化时可以直接配置好 Config 中的参数。初始化之后,如果开发者需要,也可以继续对 LCActionSheet 实例修改属性。简单代码如下:

  • Config.h:

     @interface LCActionSheetConfig : NSObject
    
     @property (nonatomic, strong) UIFont *titleFont;
    
     @property (nonatomic, strong) UIColor *titleColor;
    
     // ...
    
     + (instancetype)shared;
    
     @end
  • LCActionSheet.m:

     @implementation LCActionSheet
    
     // 私有方法, 由框架调用, 初始化时传入 Config 单例
     - (instancetype)initWithConfig:(LCActionSheetConfig *)config;
    
     @end
  • 开发者外部调用:

     // 这段代码只需要初始化一次,需要在第一次初始化 LCActionSheet 前调用
     LCActionSheetConfig *config = [LCActionSheetConfig shared];
     config.titleFont = myFont;
     config.titleColor = myColor;
     // ...
    
     // LCActionSheet 框架的使用跟之前并无区别, 框架内会通过统一配置的 Config 来初始化当前实例
     LCActionSheet *sheet = [[LCActionSheet alloc] initWithTitle:@"Title" cancelButtonTitle:@"Cancel" clicked:nil otherButtonTitles:@"OK", nil];
    
     // 同时允许用户继续配置参数
     sheet.titleFont = anotherFont;
    
     [sheet show];

至于 title contentInset 这个需求我记下来,时间充足的话尽快实现,最近公司业务有点忙。

@seekcx
Copy link
Author

seekcx commented Nov 28, 2016

恩,这种方式挺好的。

还有一个问题:
貌似swift里不能通过实例调用appendButtonTitles这个方法。

@iTofu
Copy link
Owner

iTofu commented Nov 28, 2016 via email

iTofu pushed a commit that referenced this issue Nov 29, 2016
@iTofu
Copy link
Owner

iTofu commented Nov 29, 2016

Hi,全局配置和 titleEdgeInsets 都已实现,更新到 V 2.7.0 就可以了!我测试 ok,你试一下看有没有问题。

@iTofu
Copy link
Owner

iTofu commented Nov 29, 2016

-appendButtonTitles: 方法貌似是 Swift 没有桥接成功……回头再看吧……

@seekcx
Copy link
Author

seekcx commented Nov 30, 2016

恩恩,目前这样就只需要配置一次就可以了,而且titleEdgeInsets实现了,非常棒👍

@seekcx seekcx closed this as completed Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants