Nicejinux/NXDrawKit

Default width

ak0815 opened this issue · 10 comments

Hi,

thanks for the great module :-)

How can I set default color and width?

Thanks
Andy

Thanks for using my lib. ;)

You mean, you want to set default values for color and width when you use NXDrawKit without delegate?
If it's yes, NXDrawKit doesn't have that feature yet.

I think just add some delegate method or make delegate extension file for default values what you want to set.
It's very easy.

Thanks.

Yes I mean to set default values like color, width and alpha. Can you add this feature for me :-)?

Thanks
Andy

It's not that hard to implement, but why do you need this features?

You can set all values with delegate, and if you don't want to add delegate on your viewController,
you can make new class for delegate extension.

or, I can add some codes for using block.

I think setting default values when the class is initialized is very ugly.
like this.

NXPalete *palete = [[NXPalete alloc] initWithColors:@[RGB(@"ffffff"), RGB(@"ffffff"),RGB(@"ffffff"),RGB(@"ffffff"),RGB(@"ffffff"), .... ];
 

Why do you want that feature?
and why don't want to use delegate?

Can you explain it? if it's understandable, I will make it for you.

Thanks.

Can you make an example how I can add this with delegate?
I misunderstood you

Ah.. ok. I understood why you asked me.

You can find ViewController.swift in my Example project.
open it, and scroll to bottom. and you can see it this codes.

    // tag can be 1 ... 12
    func colorWithTag(_ tag: NSInteger) -> UIColor? {
        if tag == 4 {
            // if you return clearColor, it will be eraser
            return UIColor.clear
        }
        return nil
    }
    
    // tag can be 1 ... 4
//    func widthWithTag(tag: NSInteger) -> CGFloat {
//        if tag == 1 {
//            return 5.0
//        }
//        return -1
//    }
    // tag can be 1 ... 3
//    func alphaWithTag(tag: NSInteger) -> CGFloat {
//        return -1
//    }

if you want to change the color what you want, make it like this.
tag is an index of the position on the palette.

func colorWithTag(_ tag: NSInteger) -> UIColor? {
    if tag == 1 {
        return UIColor.blueColor 
    } else if tag == 2 {
        return UIColor.redColor
    }
    .
    .
    .

}

Other methods are same. You can customize it in the delegate method.

func colorWithTag(tag: NSInteger) -> UIColor?
  • tag can be 1 ... 12
  • If you return nil, the color of tag will set with default color provided by NXDrawKit.
  • If you return clearColor() , the color of tag will be Eraser.
func alphaWithTag(tag: NSInteger) -> CGFloat
  • tag can be 1 ... 3
  • If you return -1, the alpha of tag will set with default alpha provided by NXDrawKit.
func widthWithTag(tag: NSInteger) -> CGFloat
  • tag can be 1 ... 4
  • If you return -1, the width of tag will set with default width provided by NXDrawKit.

Thanks :-)

On more thing:

I have added:

`fileprivate func setupPalette() {
self.view.backgroundColor = UIColor.white

    let paletteView = Palette()

   widthWithTag(tag: 2)

    paletteView.delegate = self
    paletteView.setup()
    self.view.addSubview(paletteView)
    self.paletteView = paletteView
    let paletteHeight = paletteView.paletteHeight()
    paletteView.frame = CGRect(x: 0, y: self.view.frame.height - paletteHeight, width: self.view.frame.width, height: paletteHeight)

    
}`

func widthWithTag(tag: NSInteger) -> CGFloat { print("widthtag") print(tag) if tag == 1 { return 5.0 } if tag == 2 { return 1.0 } if tag == 3 { return 3.0 } return 5.0 }

But it didn´t work. Always the biggest brush is default.
Can you help me?

Andy

I'll check and let you know.

delegate method parameter is mismatched.

    // tag can be 1 ... 4
    func widthWithTag(_ tag: NSInteger) -> CGFloat {
        if tag == 1 {
            return 5.0
        }
        return -1
    }

use this codes.

sorry.

Perfekt it works!!

Thanks