Skip to content

Commit a976835

Browse files
author
叶晓冬
committed
Merge branch 'master' into pr/145
2 parents 0d51830 + 86d8b1a commit a976835

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Simply add the following lines to your `Podfile`:
5151
# required by Cocoapods 0.36.0.rc.1 for Swift Pods
5252
use_frameworks!
5353

54-
pod 'RSBarcodes_Swift', '~> 5.1.0'
54+
pod 'RSBarcodes_Swift', '~> 5.1.1'
5555
```
5656

5757
You will need to import RSBarcodes_Swift manually in the ViewController file after creating the file using wizard.
@@ -63,7 +63,7 @@ You will need to import RSBarcodes_Swift manually in the ViewController file aft
6363
Simply add the following line to your `Cartfile`:
6464

6565
```ruby
66-
github "yeahdongcn/RSBarcodes_Swift" >= 5.1.0
66+
github "yeahdongcn/RSBarcodes_Swift" >= 5.1.1
6767
```
6868

6969
You will need to import RSBarcodes_Swift manually in the ViewController file after creating the file using wizard.

RSBarcodes_Swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "RSBarcodes_Swift"
3-
s.version = "5.1.0"
3+
s.version = "5.1.1"
44
s.summary = "1D and 2D barcodes reader and generators for iOS 9 with delightful controls. Now Swift. "
55
s.homepage = "https://github.com/yeahdongcn/RSBarcodes_Swift"
66
s.license = { :type => 'MIT', :file => 'LICENSE.md' }

Source/RSCodeGenerator.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import AVFoundation
1212
import CoreImage
1313

1414
let DIGITS_STRING = "0123456789"
15+
let BARCODE_DEFAULT_HEIGHT = 28
1516

1617
// Controls the amount of additional data encoded in the output image to provide error correction.
1718
// Higher levels of error correction result in larger output images but allow larger areas of the code to be damaged or obscured without.
@@ -106,9 +107,13 @@ open class RSAbstractCodeGenerator : RSCodeGenerator {
106107
// Top spacing = 1.5
107108
// Bottom spacing = 2
108109
// Left & right spacing = 2
109-
// Height = 28
110110
let width = length + 4
111-
let size = CGSize(width: CGFloat(width), height: 28)
111+
// Calculate the correct aspect ratio, so that the resulting image can be resized to the target size
112+
var height = BARCODE_DEFAULT_HEIGHT
113+
if let targetSize = targetSize {
114+
height = Int(targetSize.height / targetSize.width * CGFloat(width))
115+
}
116+
let size = CGSize(width: CGFloat(width), height: CGFloat(height))
112117
UIGraphicsBeginImageContextWithOptions(size, false, 1)
113118
if let context = UIGraphicsGetCurrentContext() {
114119
context.setShouldAntialias(false)

0 commit comments

Comments
 (0)