簡體   English   中英

iOS 8 UITableViewRowAction:向左滑動,圖像?

[英]iOS 8 UITableViewRowAction: Swipe Left, Images?

我剛剛在iOS8上遇到過這個新的API。 但是,如果可以使用圖像而不是文本並允許左右滑動,我無法找到任何解決方案? 這甚至可能嗎? 我發現的唯一實現是:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        // maybe show an action sheet with more options
        [self.tableView setEditing:NO];
    }];
    moreAction.backgroundColor = [UIColor blueColor];

    UITableViewRowAction *moreAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        [self.tableView setEditing:NO];
    }];
    moreAction2.backgroundColor = [UIColor blueColor];

    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }];

    return @[deleteAction, moreAction, moreAction2];
}

不,我認為沒有可能進行正確的滑動(無論如何都要使用UITableViewCell)。 但是,您可以使用colorWithPatternImage:設置其背景顏色,為按鈕使用圖像。 按鈕的寬度似乎取決於標題的長度,因此如果要更改寬度(並且沒有任何可見標題),請使用包含所需空格的標題。

在Swift中它將是:

deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)

將圖像添加到滑動視圖時,此答案可能會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM