2

UITableViewRowAction's以下のように、ソースコードに3つあります。

- (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条件では無効として作成されます。

ただし、のみが有効で他の 2 つが無効な 場合、 の は他の 2 つbackgroundColormessageAction影響します。messageAction

これを確認するために、最初に配置することでボタンの表示順序を逆にしましたcancelAction。そうすれば、キャンセル ボタンbackgroundColorは他の 2 つに影響します。

backgroundColor各ボタンの視覚化 od プロパティを修正するにはどうすればよいですか?

4

2 に答える 2

0

次のように tableview デリゲート メソッドをオーバーライドeditActionsForRowAtIndexPathします。

-(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 に答える
0

背景色にはアルファ値があります。アクション ビューは、右端のボタンから内側に向​​かって重ねて描画されます。

アルファなしの色を使用し、他のボタンの背景色と混ざらないようにします。

于 2016-11-24T22:59:33.767 に答える