首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOS11 UIContextualAction放置图像颜色文本

IOS11 UIContextualAction放置图像颜色文本
EN

Stack Overflow用户
提问于 2017-09-25 14:32:35
回答 4查看 5.1K关注 0票数 11

为了防止图片如何还原本色,我现在把图片都放在白色的地方

代码语言:javascript
复制
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0))
{

 UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL))
    {
        NSLog(@"------------------>%@",sourceView);
        completionHandler (YES);
    }];

    deleteRowAction.image = [UIImage imageNamed:@"heart"];

    UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
         return config;


    return nil;

}
EN

回答 4

Stack Overflow用户

发布于 2019-04-16 18:57:59

RSSReaderMaker解决方案适用于小更新Swift 5:

代码语言:javascript
复制
class ImageWithoutRender: UIImage {
    override func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage {
        return self
    }
}

trailingSwipeActionsConfigurationForRowAtleadingSwipeActionsConfigurationForRowAt

使用:

代码语言:javascript
复制
if let cgImageX =  UIImage(named: "x_blue_big")?.cgImage {
     action.image = ImageWithoutRender(cgImage: cgImageX, scale: UIScreen.main.nativeScale, orientation: .up)
}
票数 15
EN

Stack Overflow用户

发布于 2018-07-19 20:33:55

您可以通过UIAppearance修改UIImage的通用tintColor来更改图片的颜色,例如:

UIImageView.appearance().tintColor = .yellow

但这会将该(默认)色调颜色应用于应用程序中的所有图像视图,因此您可以通过以下方式将其限制为表视图中的图像视图:

UIImageView.appearance(whenContainedInInstancesOf: [UITableView.self]).tintColor = .yellow

您还可以指定自己的UITableView子类(如果有)。

票数 6
EN

Stack Overflow用户

发布于 2019-03-22 16:43:02

我解决了这个问题。第一步是用随机名称声明UIImage的一个子类,并覆盖它的imageWithRenderingMode:方法。我想做这个

代码语言:javascript
复制
@implementation FakeImage

- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode
{
     return self;
}
@end

第二步,在给UIContextualAction赋值时,使用这个类,注意使用initWithCGImage方法实例化。

代码语言:javascript
复制
UIContextualAction* action = xxxx;
action.image = [[FakeImage alloc] initWithCGImage:[UIImage imageNamed:@"zoo_icon_time"].CGImage scale:2 orientation:UIImageOrientationUp];

把它做完。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46398910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档