字串轉 Barcode 圖
發表於 : 週四 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!)
}
}