Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update McPicker.swift for dynamic height component for picker view #64

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Example/McPicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-McPicker_Tests/Pods-McPicker_Tests-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-McPicker_Tests/Pods-McPicker_Tests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/McPicker/McPicker.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -282,7 +282,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-McPicker_Tests/Pods-McPicker_Tests-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-McPicker_Tests/Pods-McPicker_Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
7218E36A1F0EA822003423A2 /* ShellScript */ = {
Expand Down Expand Up @@ -322,7 +322,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-McPicker_Example/Pods-McPicker_Example-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-McPicker_Example/Pods-McPicker_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/McPicker/McPicker.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -331,7 +331,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-McPicker_Example/Pods-McPicker_Example-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-McPicker_Example/Pods-McPicker_Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
C653CADCE98997CF8CE190CF /* [CP] Check Pods Manifest.lock */ = {
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- McPicker (2.0.0)
- McPicker (2.0.2)

DEPENDENCIES:
- McPicker (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
McPicker: 184bd2403f48f1b69e8384d2dbcd4fcff4c0df5f
McPicker: ef2efeb2357f1a1e803eae239f021d75e07aeec7

PODFILE CHECKSUM: 7f68cc3d721452977903943f3af774acc3f68ed4

COCOAPODS: 1.5.0
COCOAPODS: 1.8.4
2 changes: 1 addition & 1 deletion McPicker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'McPicker'
s.version = '2.0.1'
s.version = '2.0.3'
s.summary = 'McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.'
s.swift_version = '4.2'

Expand Down
30 changes: 30 additions & 0 deletions McPicker/Classes/McPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,36 @@ extension McPicker : UIPickerViewDelegate {

return pickerLabel!
}

public func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
guard let goodLabel = label, pickerData.count == 1 else {
return 50.0
}
return self.heightForView(pickerData[0][component], font: goodLabel.font, width: pickerView.frame.size.width - 20, actualHeight: goodLabel.frame.size.height)
}

// MARK: CALCULATE HEIGHT OF VIEW BASED ON STRING LENGHT
/// CALCULATE HEIGHT OF VIEW BASED ON STRING LENGHT
///
/// - Parameters:
/// - text: text whose height is to be calculate
/// - font: Font for calculation
/// - width: Label Width
/// - actualHeight: actual Height of Label
/// - Returns: Calculated height of table View
func heightForView(_ text: String, font: UIFont, width: CGFloat, actualHeight: CGFloat) -> CGFloat {
let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: width, height: CGFloat.greatestFiniteMagnitude))
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.font = font
label.text = text
label.sizeToFit()
var height: CGFloat = 40.0
if actualHeight != 0 {
height = actualHeight
}
return max(label.frame.height, height)
}

public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if !pickerData[component].isEmpty {
Expand Down
2 changes: 1 addition & 1 deletion McPicker/Classes/McPickerBarButtonItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ open class McPickerBarButtonItem: UIBarButtonItem {
return self.init(barButtonSystemItem: barButtonSystemItem, target: mcPicker, action: #selector(McPicker.cancel))
}

public class func flexibleSpace() -> McPickerBarButtonItem {
public override class func flexibleSpace() -> McPickerBarButtonItem {
return self.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ McPicker is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod "McPicker"
pod 'McPicker', :git => 'https://github.com/KahunaSystems/McPicker-iOS.git', :tag => '2.0.3'
```

### Swift 4.2 Support

For Swift 4.2 support, please use version `2.0.0`.

```ruby
pod 'McPicker', '~> 2.0.0'
pod 'McPicker', :git => 'https://github.com/KahunaSystems/McPicker-iOS.git', :tag => '2.0.0'
```

## Author
Expand Down