2

我的源代码中有 3 个UITableViewRowAction's,如下所示:

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView
                  editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(messagePremission)
    {
        messageAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:[NSString stringWithFormat:@"%@%@", NSLocalizedString(@"message_admin", nil), activity.GroupName] handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

                }];

        messageAction.backgroundColor = [UIColor colorWithRed:82.0/255.0 green:82.0/255.0 blue:82.0/255.0 alpha:1.0];
    }
    else
    {
        messageAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:[NSString stringWithFormat:@"%@%@", NSLocalizedString(@"message_admin", nil), activity.GroupName] handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

                }];

        messageAction.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:199.0/255.0 blue:205.0/255.0 alpha:0.1];
    }

    if(editPermission)
    {
        editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:NSLocalizedString(@"edit_swipe", nil) handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

            }];

        editAction.backgroundColor = [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:1.0];
    }
    else
    {
        editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:NSLocalizedString(@"edit_swipe", nil) handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

            }];

        editAction.backgroundColor = [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:0.1];
    }
    if(cancelPermission)
    {
        cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){   
            }];

        cancelAction.backgroundColor = [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:1.0];
    }
    else
    {
        cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){   
            }];

        cancelAction.backgroundColor = [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:0.1];
    }  

    [arrButtons addObject:messageAction];
    [arrButtons addObject:editAction];
    [arrButtons addObject:cancelAction]; 

    return arrButtons;
}

在每个if条件下,一个按钮被创建为启用,而在相应的else条件下,一个按钮被创建为禁用。

但是,当仅启用而禁用 其他两个时, backgroundColorofmessageAction会影响其他两个。messageAction

为了确认这一点,我将按钮的显示顺序颠倒了,将cancelActionas first 放在了前面。这样,取消按钮会backgroundColor影响其他两个。

如何修复backgroundColor每个按钮的可视化 od 属性?

4

2 回答 2

0

您的背景颜色具有 alpha 值 - 操作视图从最右边的按钮向内重叠绘制。

使用没有 alpha 的颜色,它应该很好,并且不会与其他按钮背景颜色混合。

于 2016-11-24T22:59:33.767 回答
0

覆盖editActionsForRowAtIndexPathtableview 委托方法如下:-

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewRowAction *messageButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Message" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                    {
                                        NSLog(@"Action to perform with messageButton Button");
                                    }];
    UIColor *messageColor  = if(messagePremission == true) ? [UIColor colorWithRed:82.0/255.0 green:82.0/255.0 blue:82.0/255.0 alpha:1.0] :
        [UIColor colorWithRed:200.0/255.0 green:199.0/255.0 blue:205.0/255.0 alpha:0.1];
    messageButton.backgroundColor = messageColor;

    UITableViewRowAction *editButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                     {
                                         NSLog(@"Action to perform with editButton Button!");
                                     }];
    UIColor *editColor  = if(editPermission == true) ? [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:1.0] :
        [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:0.1];
    editButton.backgroundColor = editColor;

    UITableViewRowAction *cancelButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                     {
                                         NSLog(@"Action to perform with cancelButton");
                                     }];
    UIColor *cancelColor  = if(cancelPermission == true) ? [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:1.0] :
        [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:0.1];
    cancelButton.backgroundColor = cancelColor;

    return @[messageButton, editButton, cancelButton];
}
于 2016-08-24T12:09:08.823 回答