實際上只是把文字轉圖檔並呈現
代碼: 選擇全部
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!)
}
}