Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ xcuserdata
*.moved-aside
*.xcuserstate
*.xcscmblueprint
*.DS_Store
*.xcworkspace

## Obj-C/Swift specific
*.hmap
Expand Down
4 changes: 2 additions & 2 deletions MBRateApp/Assets/RateUs.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Oyz-Gc-1hz">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Oyz-Gc-1hz">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand Down Expand Up @@ -138,7 +138,7 @@
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<nil key="highlightedColor"/>
</label>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O8Q-2E-bsU">
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="clip" translatesAutoresizingMaskIntoConstraints="NO" id="O8Q-2E-bsU">
<rect key="frame" x="176" y="417" width="248" height="40"/>
<color key="backgroundColor" red="0.27450980390000002" green="0.62745098040000002" blue="0.77647058820000003" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
Expand Down
84 changes: 46 additions & 38 deletions MBRateApp/Classes/MBRateUsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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!
Expand All @@ -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)?
Expand All @@ -60,36 +52,47 @@ 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.callToActionButton.titleLabel?.adjustsFontSizeToFitWidth = true
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
}

for button: UIButton in self.starButtons {
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?()})
}
Expand All @@ -112,17 +115,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
Expand All @@ -136,14 +141,17 @@ 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)")!)
}

self.positiveBlock?()
}else {

guard self.shouldRate else {
self.negativeBlock?()
return
}

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?()
}
})
}
Expand Down