Using only one tool from CLImageEditor

I am working on adding text to an image. I found the CLImageEditor tool to be very good. but I only want to use a text tool with my own theme. so I can use this tool in my application. or any other tool that I can use in my application.

+3


source to share


4 answers


It is possible by tweeking the existing code as shown below:



    //First disable all the tools like below but the one you need.
          var tool = editor.toolInfo.subToolInfoWithToolName("CLRotateTool", recursive: false)
          tool.available = false

    //replace below 4 functions in CLImageEditorView Controller

    - (void)setMenuView
    {
        CGFloat x = 0;
        CGFloat W = 70;
        CGFloat H = _menuView.height;

        int toolCount = 0;
        CGFloat padding = 0;
        for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
            if(info.available){
                toolCount++;
            }
        }

        CGFloat diff = _menuView.frame.size.width - toolCount * W;
        if (0<diff && diff<2*W) {
            padding = diff/(toolCount+1);
        }

        for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
            if(!info.available){
                continue;
            }

            CLToolbarMenuItem *view = [CLImageEditorTheme menuItemWithFrame:CGRectMake(x+padding, 0, W, H) target:self action:@selector(tappedMenuView:) toolInfo:info];
            [_menuView addSubview:view];
            x += W+padding;
            [self tappedMenuView:view];

        }
        _menuView.contentSize = CGSizeMake(MAX(x, _menuView.frame.size.width+1), 0);
    }

    - (IBAction)pushedCancelBtn:(id)sender
    {
        _imageView.image = _originalImage;
        [self resetImageViewFrame];
        self.currentTool = nil;
        [self  pushedCloseBtn:nil];

    }

- (IBAction)pushedDoneBtn:(id)sender
{
    self.view.userInteractionEnabled = NO;

    [self.currentTool executeWithCompletionBlock:^(UIImage *image, NSError *error, NSDictionary *userInfo) {
        if(error){
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }
        else if(image){
            _originalImage = image;
            _imageView.image = image;

            [self resetImageViewFrame];
            self.currentTool = nil;
        }
        self.view.userInteractionEnabled = YES;
        [self pushedFinishBtn:nil];
    }];
}


    - (void)viewDidLoad
    {
        [super viewDidLoad];

        self.title = self.toolInfo.title;
        self.view.clipsToBounds = YES;
        self.view.backgroundColor = self.theme.backgroundColor;
        self.navigationController.view.backgroundColor = self.view.backgroundColor;

        if([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]){
            self.automaticallyAdjustsScrollViewInsets = NO;
        }

        if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }

        [self initNavigationBar];
        [self initMenuScrollView];
        [self initImageScrollView];


        if(_imageView==nil){
            _imageView = [UIImageView new];
            [_scrollView addSubview:_imageView];
            [self refreshImageView];
        }
        [self setMenuView];

    }

      

0


source


You can do this for every tool.



 CLImageToolInfo *tool = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];
    tool.available = NO;     // if available is set to NO, it is removed from the menu view.

      

+1


source


No, you cannot open a submenu. There may be an issue with them at https://github.com/yackle/CLImageEditor/issues

If you only want to show a few options, or you want to customize the layout of the elements, you can do it like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:image];
    editor.delegate = self;

    CLImageToolInfo *tool1 = [editor.toolInfo subToolInfoWithToolName:@"CLAdjustmentTool" recursive:NO];
    CLImageToolInfo *tool2 = [editor.toolInfo subToolInfoWithToolName:@"CLBlurTool" recursive:NO];
    CLImageToolInfo *tool3 = [editor.toolInfo subToolInfoWithToolName:@"CLRotateTool" recursive:NO];
    CLImageToolInfo *tool4 = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];

    tool1.available = NO;
    tool2.available = NO;
    tool3.available = NO;
    tool4.available = NO;
    [picker pushViewController:editor animated:YES];
}

      

+1


source


You cannot open the submenu directly.

I created a delete function to delete subordinate tools. Swift 4.2

private func removeTools(tools: [String]) {
    tools.forEach {
      guard let imageEditor = self.imageEditor else { return }
      let tool = imageEditor.toolInfo.subToolInfo(withToolName: $0, recursive: false)
      tool?.available = false
    }
  }

      

You can call like this;

removeTools(tools: ["CLFilterTool", "CLEffectTool"])

      

0


source







All Articles