字串轉 Barcode 圖

rusli
Site Admin
文章: 212
註冊時間: 週三 7月 07, 2010 9:49 pm

字串轉 Barcode 圖

文章rusli » 週四 3月 24, 2016 6:10 pm

主要目的讓紅外線掃描器可以把圖掃進去 iDevice 裡的錯覺.
實際上只是把文字轉圖檔並呈現

代碼: 選擇全部

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)

          cell.imageView?.image = description.toBarcodeImage()
       
        return cell
 }


代碼: 選擇全部

extension String
{
    func toBarcodeImage() -> UIImage? {
        let data = self.dataUsingEncoding(NSASCIIStringEncoding)
        let filter = CIFilter(name: "CICode128BarcodeGenerator")
        filter!.setValue(data, forKey: "inputMessage")
        return UIImage(CIImage: filter!.outputImage!)
    }
}

回到「Swift」

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客