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

swift 3 upddate my nigga? #5

Open
wants to merge 7 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
41 changes: 28 additions & 13 deletions AKPickerView/AKPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ private class AKCollectionViewCell: UICollectionViewCell {
var imageView: UIImageView!
var font = UIFont.systemFontOfSize(UIFont.systemFontSize())
var highlightedFont = UIFont.systemFontOfSize(UIFont.systemFontSize())
var _selected: Bool = false {
didSet(selected) {
let animation = CATransition()
animation.type = kCATransitionFade
animation.duration = 0.15
self.label.layer.addAnimation(animation, forKey: "")
self.label.font = self.selected ? self.highlightedFont : self.font
}
}
var lineView: UIView?

override var selected: Bool {
didSet {
let animation = CATransition()
animation.type = kCATransitionFade
animation.duration = 0.15
self.label.layer.addAnimation(animation, forKey: "")
self.label.font = self.selected ? self.highlightedFont : self.font
lineView?.layer.addAnimation(animation, forKey: "animation.alpha")
lineView?.alpha = selected ? 1.0 : 0.0
}
}

func setHighlightedTextColor(color: UIColor) {
label.highlightedTextColor = color
lineView?.backgroundColor = color
}

func initialize() {
self.layer.doubleSided = false
self.layer.shouldRasterize = true
Expand All @@ -84,6 +93,12 @@ private class AKCollectionViewCell: UICollectionViewCell {
self.label.font = self.font
self.label.autoresizingMask = [.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleRightMargin]
self.contentView.addSubview(self.label)

// lineView = UIView(frame: CGRect(origin: CGPoint(x: 0, y: contentView.bounds.size.height - 2), size: CGSize(width: contentView.bounds.size.width, height: 2)))
// lineView?.alpha = 0.0
// lineView?.backgroundColor = UIColor.blueColor()
// self.lineView?.autoresizingMask = [.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleRightMargin]
// self.contentView.addSubview(self.lineView)

self.imageView = UIImageView(frame: self.contentView.bounds)
self.imageView.backgroundColor = UIColor.clearColor()
Expand Down Expand Up @@ -286,7 +301,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD

// MARK: Readonly Properties
/// Readonly. Index of currently selected item.
private(set) var selectedItem: Int = 0
public private(set) var selectedItem: Int = 0
/// Readonly. The point at which the origin of the content view is offset from the origin of the picker view.
public var contentOffset: CGPoint {
get {
Expand Down Expand Up @@ -518,9 +533,9 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(NSStringFromClass(AKCollectionViewCell.self), forIndexPath: indexPath) as! AKCollectionViewCell
if let title = self.dataSource?.pickerView?(self, titleForItem: indexPath.item) {
cell.label.text = title
cell.setHighlightedTextColor(highlightedTextColor)
cell.label.text = title
cell.label.textColor = self.textColor
cell.label.highlightedTextColor = self.highlightedTextColor
cell.label.font = self.font
cell.font = self.font
cell.highlightedFont = self.highlightedFont
Expand All @@ -534,7 +549,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD
} else if let image = self.dataSource?.pickerView?(self, imageForItem: indexPath.item) {
cell.imageView.image = image
}
cell._selected = (indexPath.item == self.selectedItem)
cell.selected = (indexPath.item == self.selectedItem)
return cell
}

Expand Down
4 changes: 4 additions & 0 deletions AKPickerViewSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import UIKit
class ViewController: UIViewController, AKPickerViewDataSource, AKPickerViewDelegate {

@IBOutlet var pickerView: AKPickerView!
@IBOutlet weak var leftArrow: UIButton!
@IBOutlet weak var rigthArrow: UIButton!

let titles = ["Tokyo", "Kanagawa", "Osaka", "Aichi", "Saitama", "Chiba", "Hyogo", "Hokkaido", "Fukuoka", "Shizuoka"]

Expand All @@ -22,7 +24,9 @@ class ViewController: UIViewController, AKPickerViewDataSource, AKPickerViewDele
self.pickerView.font = UIFont(name: "HelveticaNeue-Light", size: 20)!
self.pickerView.highlightedFont = UIFont(name: "HelveticaNeue", size: 20)!
self.pickerView.pickerViewStyle = .Wheel

self.pickerView.maskDisabled = false
self.pickerView.highlightedTextColor = UIColor.blueColor()
self.pickerView.reloadData()
}

Expand Down