lixiang1994 / LEEAlert

优雅的可自定义 Alert ActionSheet
MIT License
1.3k stars 204 forks source link

关于只添加customView,顶部留白问题 #169

Closed Nododo closed 2 years ago

Nododo commented 2 years ago

读过源码发下如果只添加customView,顶部留白问题为下面代码所致

item.insets = UIEdgeInsetsMake(5, 0, 5, 0);

这个属性能暴露出来支持自定义吗?

代码如下:

LEEAlert
    .alert
    .config
    .LeeClickBackgroundClose(YES)
    .LeeBackGroundColor(UIColor.redColor)
    .LeeHeaderInsets(UIEdgeInsetsZero)
    .LeeAddCustomView(^(LEECustomView * _Nonnull custom) {
        custom.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - Scale(80), Scale(80))];
        custom.view.backgroundColor = kRandomColor;
    })
    .LeeAddCustomView(^(LEECustomView * _Nonnull custom) {
        custom.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - Scale(200), Scale(80))];
        custom.view.backgroundColor = kRandomColor;
    })
    .LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"兑换积分";
        action.cornerRadius = Scale(8);
        action.borderWidth = 1;
        action.borderColor = kRandomColor;
        action.insets = UIEdgeInsetsMake(20, 20, 20, 20);
        action.borderPosition = LEEActionBorderPositionTop
        | LEEActionBorderPositionBottom
        | LEEActionBorderPositionLeft
        | LEEActionBorderPositionRight;
    })
    .LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"水晶兑换";
        action.cornerRadius = Scale(8);
        action.backgroundColor = kRandomColor;
        action.insets = UIEdgeInsetsMake(20, 20, 20, 20);
    })
    .LeeItemInsets(UIEdgeInsetsZero)
    .LeeShow();
Nododo commented 2 years ago

或者说 如果自定义视图为第一个视图,顶部距离默认为0

lixiang1994 commented 2 years ago

你看这样呢?

LEEAlert
    .alert
    .config
    .LeeClickBackgroundClose(YES)
    .LeeBackGroundColor(UIColor.redColor)
    .LeeHeaderInsets(UIEdgeInsetsZero)
    .LeeAddCustomView(^(LEECustomView * _Nonnull custom) {
        custom.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - Scale(80), Scale(80))];
        custom.view.backgroundColor = kRandomColor;
    })
    .LeeItemInsets(UIEdgeInsetsZero)
    .LeeAddCustomView(^(LEECustomView * _Nonnull custom) {
        custom.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - Scale(200), Scale(80))];
        custom.view.backgroundColor = kRandomColor;
    })
    .LeeItemInsets(UIEdgeInsetsZero)
    .LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"兑换积分";
        action.cornerRadius = Scale(8);
        action.borderWidth = 1;
        action.borderColor = kRandomColor;
        action.insets = UIEdgeInsetsMake(20, 20, 20, 20);
        action.borderPosition = LEEActionBorderPositionTop
        | LEEActionBorderPositionBottom
        | LEEActionBorderPositionLeft
        | LEEActionBorderPositionRight;
    })
    .LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"水晶兑换";
        action.cornerRadius = Scale(8);
        action.backgroundColor = kRandomColor;
        action.insets = UIEdgeInsetsMake(20, 20, 20, 20);
    })
    .LeeShow();
Nododo commented 2 years ago

你看这样呢?

LEEAlert
    .alert
    .config
    .LeeClickBackgroundClose(YES)
    .LeeBackGroundColor(UIColor.redColor)
    .LeeHeaderInsets(UIEdgeInsetsZero)
    .LeeAddCustomView(^(LEECustomView * _Nonnull custom) {
        custom.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - Scale(80), Scale(80))];
        custom.view.backgroundColor = kRandomColor;
    })
    .LeeItemInsets(UIEdgeInsetsZero)
    .LeeAddCustomView(^(LEECustomView * _Nonnull custom) {
        custom.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - Scale(200), Scale(80))];
        custom.view.backgroundColor = kRandomColor;
    })
    .LeeItemInsets(UIEdgeInsetsZero)
    .LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"兑换积分";
        action.cornerRadius = Scale(8);
        action.borderWidth = 1;
        action.borderColor = kRandomColor;
        action.insets = UIEdgeInsetsMake(20, 20, 20, 20);
        action.borderPosition = LEEActionBorderPositionTop
        | LEEActionBorderPositionBottom
        | LEEActionBorderPositionLeft
        | LEEActionBorderPositionRight;
    })
    .LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"水晶兑换";
        action.cornerRadius = Scale(8);
        action.backgroundColor = kRandomColor;
        action.insets = UIEdgeInsetsMake(20, 20, 20, 20);
    })
    .LeeShow();

wow 可以的

看来我代码还是没吃透啊

谢谢啦!

lixiang1994 commented 2 years ago

. LeeItemInsets()会影响它前面的Item

Nododo commented 2 years ago

. LeeItemInsets()会影响它前面的Item

嗯嗯