Skip to content

Commit

Permalink
Bug Fixes and UI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoliveira committed Jul 22, 2016
1 parent 4610927 commit c4433a3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion BOShareComposer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'BOShareComposer'
s.version = '0.2.2'
s.version = '0.3.0'
s.summary = 'A simple text + URL share composer'
s.description = <<-DESC
Composer like share to do custom shares, example: share via direct message twitter they dont have
Expand Down
4 changes: 2 additions & 2 deletions BOShareComposer/Classes/ShareOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct ShareOptions {

// Buttons tint color
public var tintColor: UIColor?
public var tintColor: UIColor

// Composer title
public var title: String
Expand All @@ -28,7 +28,7 @@ public struct ShareOptions {
// Keyboard appearence
public var keyboardAppearance: UIKeyboardAppearance

public init (tintColor: UIColor? = nil, title: String = "Share", dismissText: String = "Cancel",
public init (tintColor: UIColor = UIView().tintColor, title: String = "Share", dismissText: String = "Cancel",
confirmText: String = "Send", showMetadata: Bool = true,
keyboardAppearance: UIKeyboardAppearance = .Dark) {
self.tintColor = tintColor
Expand Down
58 changes: 37 additions & 21 deletions BOShareComposer/Classes/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public extension ShareViewController {
options: ShareOptions = ShareOptions(),
completion: ((Bool, ShareContent?) -> ())) {

viewController.navigationController?.modalPresentationStyle = .OverCurrentContext
viewController.modalPresentationStyle = .OverCurrentContext

let shareViewController = ShareViewController()
shareViewController.completion = completion
shareViewController.options = options
shareViewController.shareContent = shareContent
shareViewController.modalPresentationStyle = .OverCurrentContext
viewController.presentViewController(shareViewController, animated: false, completion: nil)
}
}
Expand Down Expand Up @@ -60,8 +60,12 @@ public class ShareViewController: UIViewController {
}
dismissButton.tintColor = options.tintColor
dismissButton.setTitle(options.dismissText, forState: .Normal)
confirmButton.tintColor = options.tintColor
dismissButton.setTitleColor(options.tintColor, forState: .Normal)

confirmButton.titleLabel?.textColor = options.tintColor
confirmButton.setTitle(options.confirmText, forState: .Normal)
confirmButton.setTitleColor(options.tintColor, forState: .Normal)

popupTitle.text = options.title
popupBody.resignFirstResponder()
popupBody.keyboardAppearance = options.keyboardAppearance
Expand Down Expand Up @@ -89,19 +93,24 @@ public class ShareViewController: UIViewController {
private var completion: ((Bool, ShareContent?) -> ())?

lazy var dismissButton: UIButton = {
let button = UIButton(type: UIButtonType.System)
let button = UIButton(type: .Custom)
button.addTarget(self, action: #selector(cancelAction), forControlEvents: .TouchUpInside)
button.titleLabel?.font = UIFont.systemFontOfSize(15)
button.titleLabel?.textAlignment = .Right
return button
}()

lazy var confirmButton: UIButton = {
let button = UIButton(type: UIButtonType.System)
let button = UIButton(type: .Custom)
button.addTarget(self, action: #selector(sendAction), forControlEvents: .TouchUpInside)
button.titleLabel?.font = UIFont.boldSystemFontOfSize(17)
button.titleLabel?.textAlignment = .Left
return button
}()

lazy var popupTitle: UILabel = {
let label = UILabel()
label.font = UIFont.systemFontOfSize(17)
return label
}()

Expand All @@ -116,7 +125,7 @@ public class ShareViewController: UIViewController {
textField.editable = true
textField.backgroundColor = UIColor.clearColor()
textField.scrollEnabled = true
textField.font = UIFont.systemFontOfSize(18)
textField.font = UIFont.systemFontOfSize(17)
textField.becomeFirstResponder()
return textField
}()
Expand All @@ -126,12 +135,14 @@ public class ShareViewController: UIViewController {
imageView.contentMode = .ScaleAspectFill
imageView.clipsToBounds = true
imageView.backgroundColor = UIColor.whiteColor()
imageView.layer.borderWidth = 1
imageView.layer.borderColor = UIColor.blackColor().colorWithAlphaComponent(0.3).CGColor
return imageView
}()

lazy var backgroundView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.7)
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.6)
return view
}()

Expand Down Expand Up @@ -160,6 +171,10 @@ public class ShareViewController: UIViewController {
hideView()
}

public override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}

func cancelAction() {
shareContent?.text = popupBody.text
completion?(false, shareContent)
Expand Down Expand Up @@ -191,8 +206,6 @@ extension ShareViewController: WKNavigationDelegate {
self.snapWebView(webView)
})
}


}

extension ShareViewController {
Expand Down Expand Up @@ -222,7 +235,7 @@ extension ShareViewController {
}

private func showView() {
UIView.animateWithDuration(0.5) {
UIView.animateWithDuration(0.7) {
self.containerView.alpha = 1
}
}
Expand All @@ -241,7 +254,7 @@ extension ShareViewController {
}

private func setupViews() {
view.backgroundColor = UIColor.whiteColor()
view.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.1)
view.addSubview(backgroundView)
backgroundView.snp_makeConstraints { make in
make.edges.equalTo(self.view)
Expand All @@ -250,22 +263,24 @@ extension ShareViewController {
view.addSubview(containerView)

containerView.snp_makeConstraints { make in
make.top.equalTo(backgroundView).inset(60)
make.bottom.equalTo(backgroundView).inset(360)
make.left.equalTo(backgroundView).inset(16)
make.right.equalTo(backgroundView).inset(16)
}

let contentView = containerView.contentView
contentView.addSubview(dismissButton)
dismissButton.snp_makeConstraints { make in
make.top.equalTo(contentView).inset(4)
make.left.equalTo(contentView).inset(8)
make.top.equalTo(contentView)
make.left.equalTo(contentView).inset(12)
make.height.equalTo(40)
}

contentView.addSubview(confirmButton)
confirmButton.snp_makeConstraints { make in
make.top.equalTo(contentView).inset(4)
make.right.equalTo(contentView).inset(8)
make.top.equalTo(contentView)
make.right.equalTo(contentView).inset(12)
make.height.equalTo(40)
}

contentView.addSubview(titleDivider)
Expand All @@ -278,9 +293,10 @@ extension ShareViewController {

contentView.addSubview(popupTitle)
popupTitle.snp_makeConstraints { make in
make.top.equalTo(contentView)
make.bottom.equalTo(titleDivider.snp_top)
make.top.equalTo(contentView).priorityMedium()
make.bottom.equalTo(titleDivider.snp_top).priorityMedium()
make.centerX.equalTo(contentView)
make.centerY.equalTo(dismissButton).priorityHigh()
make.left.equalTo(dismissButton.snp_right).priorityLow()
make.right.equalTo(confirmButton.snp_left).priorityLow()
}
Expand All @@ -292,22 +308,22 @@ extension ShareViewController {
make.left.equalTo(contentView).inset(8)
make.right.equalTo(contentView).inset(8)
make.bottom.equalTo(contentView).inset(8)
make.height.equalTo(140)
make.height.equalTo(160)
}

dummyContentView.addSubview(metadataImageView)
metadataImageView.snp_makeConstraints { make in
make.right.equalTo(dummyContentView)
make.height.equalTo(showMetadata ? metadataImageViewSize.height : 0)
make.width.equalTo(showMetadata ? metadataImageViewSize.width : 0)
make.centerY.equalTo(dummyContentView)
make.top.equalTo(dummyContentView).inset(8)
}

dummyContentView.addSubview(popupBody)
popupBody.snp_makeConstraints { make in
make.top.equalTo(dummyContentView)
make.left.equalTo(dummyContentView)
make.right.equalTo(metadataImageView.snp_left)
make.right.equalTo(metadataImageView.snp_left).offset(-4)
make.bottom.equalTo(dummyContentView)
}

Expand Down
15 changes: 5 additions & 10 deletions BOShareComposer/Classes/UIview+Screenshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ import UIKit
extension UIView{

var screenshot: UIImage? {

UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, 0)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}

self.layer.renderInContext(context)
let screenShot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return screenShot
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
2 changes: 1 addition & 1 deletion Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c4433a3

Please sign in to comment.