【问题标题】:Equivalent of Obj-C alloc statement in swiftswift中Obj-C alloc语句的等价物
【发布时间】:2014-09-30 09:45:24
【问题描述】:

我想快速使用这个库。它是用 Obj-C 编写的。

我已经添加了标题和桥接等,现在我不知道这个语句的等价物是什么:

        //Color did change block declaration
    NKOColorPickerDidChangeColorBlock colorDidChangeBlock = ^(UIColor *color){
        //Your code handling a color change in the picker view.
    };

    NKOColorPickerView *colorPickerView = [[NKOColorPickerView alloc] initWithFrame:CGRectMake(0, 0, 300, 340) color:[UIColor blueColor] andDidChangeColorBlock:colorDidChangeBlock];

    //Add color picker to your view
    [self.view addSubview:colorPickerView];

【问题讨论】:

    标签: objective-c iphone xcode swift alloc


    【解决方案1】:
    let colorPickerView = NKOColorPickerView(frame: CGRect(x: 0, y: 0, width: 300, height: 340), color: UIColor.blueColor()) { (color) -> Void in
        // Your code handling a color change in the picker view.
    }
    
    view.addSubview(colorPickerView)
    

    var colorDidChangeBlock: NKOColorPickerDidChangeColorBlock = { (color) in
        // Your code handling a color change in the picker view.
    }
    
    let colorPickerView = NKOColorPickerView(frame: CGRect(x: 0, y: 0, width: 300, height: 340), color: UIColor.blueColor(), andDidChangeColorBlock: colorDidChangeBlock)
    view.addSubview(colorPickerView)
    

    我更喜欢第一种方式。它更清晰,更易于阅读。

    【讨论】:

    • 哇,太棒了!谢谢!
    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多