From 26303be5909c6b00cd0ad180eb538e0a3b512036 Mon Sep 17 00:00:00 2001 From: Max Tymchii Date: Wed, 29 Jun 2016 16:54:12 +0300 Subject: [PATCH 1/5] Update git ignore. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5e5d5ce..a363252 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ xcuserdata *.moved-aside *.xcuserstate *.xcscmblueprint +*.DS_Store +*.xcworkspace ## Obj-C/Swift specific *.hmap From 31352e0a0d70db6f3bdbb984c1ee62fc2a130565 Mon Sep 17 00:00:00 2001 From: Max Tymchii Date: Wed, 29 Jun 2016 16:58:01 +0300 Subject: [PATCH 2/5] Make more agile configuration of action buttons. Add possibility to control success level of voting. --- .../Classes/MBRateUsViewController.swift | 79 ++++++++++--------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/MBRateApp/Classes/MBRateUsViewController.swift b/MBRateApp/Classes/MBRateUsViewController.swift index b9f905b..e9fc46f 100644 --- a/MBRateApp/Classes/MBRateUsViewController.swift +++ b/MBRateApp/Classes/MBRateUsViewController.swift @@ -16,6 +16,8 @@ public struct MBRateUsInfo { public var subtitle = "Please rate your experience" public var positive = "Awesome!" public var negative = "Darn. we should have been better." + public var rateInAppStoreButtonTitle = "Rate in the AppStore" + public var sendUsFeedbackButtonTitle = "Send us feedback" public var backgroundColor = UIColor.whiteColor() public var positiveButtonColor = UIColor.blueColor() public var negativeButtonColor = UIColor.blueColor() @@ -25,22 +27,12 @@ public struct MBRateUsInfo { public var titleImage = nil as UIImage? public var dismissButtonColor = UIColor.blackColor() public var itunesId = nil as String? + public var successResult = 4 } class MBRateUsViewController : UIViewController { - required init?(coder aDecoder: NSCoder) { - shouldRate = false - let podBundle = NSBundle(forClass: self.dynamicType) - - starImageOn = UIImage(named: "rateus_on", inBundle: podBundle, compatibleWithTraitCollection: nil)! - starImageOff = UIImage(named: "rateus_off", inBundle: podBundle, compatibleWithTraitCollection: nil)! - - super.init(coder: aDecoder) - } - - @IBOutlet weak var imageView: UIImageView! @IBOutlet var resultLabel : UILabel! @IBOutlet var starsMask : UIView! @@ -51,7 +43,7 @@ class MBRateUsViewController : UIViewController { @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var dismissButton: UIButton! - var rateUsInfo : MBRateUsInfo? + var rateUsInfo = MBRateUsInfo() var positiveBlock : (()->Void)? var negativeBlock : (()->Void)? var dismissBlock : (()->Void)? @@ -60,23 +52,33 @@ class MBRateUsViewController : UIViewController { var starImageOn : UIImage var starImageOff : UIImage + + required init?(coder aDecoder: NSCoder) { + shouldRate = false + let podBundle = NSBundle(forClass: self.dynamicType) + + starImageOn = UIImage(named: "rateus_on", inBundle: podBundle, compatibleWithTraitCollection: nil)! + starImageOff = UIImage(named: "rateus_off", inBundle: podBundle, compatibleWithTraitCollection: nil)! + + super.init(coder: aDecoder) + } + override func viewDidLoad() { super.viewDidLoad() self.callToActionButton.layer.cornerRadius = 6.0 + self.titleLabel.text = self.rateUsInfo.title + self.subtitleLabel.text = self.rateUsInfo.subtitle + self.view.backgroundColor = self.rateUsInfo.backgroundColor + self.titleLabel.textColor = self.rateUsInfo.textColor + self.subtitleLabel.textColor = self.rateUsInfo.textColor + self.resultLabel.textColor = self.rateUsInfo.textColor - self.titleLabel.text = self.rateUsInfo?.title - self.subtitleLabel.text = self.rateUsInfo?.subtitle - self.view.backgroundColor = self.rateUsInfo?.backgroundColor - self.titleLabel.textColor = self.rateUsInfo?.textColor - self.subtitleLabel.textColor = self.rateUsInfo?.textColor - self.resultLabel.textColor = self.rateUsInfo?.textColor - - if let fullStar = self.rateUsInfo?.fullStarImage { + if let fullStar = self.rateUsInfo.fullStarImage { self.starImageOn = fullStar } - if let emptyStar = self.rateUsInfo?.fullStarImage { + if let emptyStar = self.rateUsInfo.fullStarImage { self.starImageOff = emptyStar } @@ -84,12 +86,12 @@ class MBRateUsViewController : UIViewController { button.setImage(starImageOff, forState: .Normal) } - self.imageView.image = self.rateUsInfo?.titleImage + self.imageView.image = self.rateUsInfo.titleImage - self.dismissButton.tintColor = self.rateUsInfo?.dismissButtonColor + self.dismissButton.tintColor = self.rateUsInfo.dismissButtonColor } - + @IBAction func dismiss(sender: UIButton) { self.dismissViewControllerAnimated(true, completion: { _ in self.dismissBlock?()}) } @@ -112,17 +114,19 @@ class MBRateUsViewController : UIViewController { @IBAction func starTouched(sender: UIButton) { self.starsMask.hidden = false - if sender.tag >= 4 { - self.resultLabel.text = self.rateUsInfo?.positive - self.callToActionButton.setTitle("Rate in the AppStore", forState: .Normal) + + if sender.tag >= self.rateUsInfo.successResult { + self.resultLabel.text = self.rateUsInfo.positive + self.callToActionButton + .setTitle(self.rateUsInfo.rateInAppStoreButtonTitle, forState: .Normal) self.shouldRate = true - self.callToActionButton.backgroundColor = self.rateUsInfo?.positiveButtonColor + self.callToActionButton.backgroundColor = self.rateUsInfo.positiveButtonColor } else { - self.resultLabel.text = self.rateUsInfo?.negative - self.callToActionButton.setTitle("Send us feedback", forState: .Normal) + self.resultLabel.text = self.rateUsInfo.negative + self.callToActionButton.setTitle(self.rateUsInfo.sendUsFeedbackButtonTitle, forState: .Normal) self.shouldRate = false - self.callToActionButton.backgroundColor = self.rateUsInfo?.negativeButtonColor + self.callToActionButton.backgroundColor = self.rateUsInfo.negativeButtonColor } self.resultLabel.alpha = 0.0 self.callToActionButton.alpha = 0.0 @@ -137,12 +141,15 @@ class MBRateUsViewController : UIViewController { @IBAction func callToActionTouched(sender: UIButton) { self.dismissViewControllerAnimated(true, completion: { if self.shouldRate { - if let itunesId = self.rateUsInfo?.itunesId { - UIApplication.sharedApplication().openURL(NSURL(string: "http://itunes.apple.com/app/id\(itunesId)")!) + if let itunesId = self.rateUsInfo.itunesId, + url = NSURL(string: "http://itunes.apple.com/app/id\(itunesId)") + where UIApplication.sharedApplication().canOpenURL(url) { + UIApplication.sharedApplication().openURL(url) + self.positiveBlock?() + + return } - - self.positiveBlock?() - }else { + self.negativeBlock?() } }) From e6a2bdfec670e6965c26dbec5b2c1b0a2ffe4b87 Mon Sep 17 00:00:00 2001 From: Max Tymchii Date: Wed, 29 Jun 2016 17:15:09 +0300 Subject: [PATCH 3/5] Make action button title font size fit. --- MBRateApp/Assets/RateUs.storyboard | 4 ++-- MBRateApp/Classes/MBRateUsViewController.swift | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MBRateApp/Assets/RateUs.storyboard b/MBRateApp/Assets/RateUs.storyboard index d8c82ca..249d8e8 100644 --- a/MBRateApp/Assets/RateUs.storyboard +++ b/MBRateApp/Assets/RateUs.storyboard @@ -1,5 +1,5 @@ - + @@ -138,7 +138,7 @@ -