From 8416abaed4b2f109d12c70e360d27297df41ae90 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Mon, 10 Aug 2015 16:22:07 +0800 Subject: [PATCH] refactor SayHiView to BottomButtonView --- Yep.xcodeproj/project.pbxproj | 8 +- Yep/Base.lproj/Main.storyboard | 2 +- .../Profile/ProfileViewController.swift | 4 +- Yep/Views/SayHi/BottomButtonView.swift | 77 +++++++++++++++++++ Yep/Views/SayHi/SayHiView.swift | 76 ------------------ 5 files changed, 84 insertions(+), 83 deletions(-) create mode 100644 Yep/Views/SayHi/BottomButtonView.swift delete mode 100644 Yep/Views/SayHi/SayHiView.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 5d9b80ee..4d100bfd 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -207,7 +207,7 @@ 50E114F91ABC137A00F13000 /* YepServiceSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E114F81ABC137A00F13000 /* YepServiceSync.swift */; }; 50E114FC1ABC549300F13000 /* ContactsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E114FA1ABC549300F13000 /* ContactsCell.swift */; }; 50E114FD1ABC549300F13000 /* ContactsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50E114FB1ABC549300F13000 /* ContactsCell.xib */; }; - 50E18BB71B180F7D0076C3C6 /* SayHiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E18BB61B180F7D0076C3C6 /* SayHiView.swift */; }; + 50E18BB71B180F7D0076C3C6 /* BottomButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E18BB61B180F7D0076C3C6 /* BottomButtonView.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -444,7 +444,7 @@ 50E114F81ABC137A00F13000 /* YepServiceSync.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepServiceSync.swift; path = Services/YepServiceSync.swift; sourceTree = ""; }; 50E114FA1ABC549300F13000 /* ContactsCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactsCell.swift; path = Views/Cells/Contacts/ContactsCell.swift; sourceTree = ""; }; 50E114FB1ABC549300F13000 /* ContactsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ContactsCell.xib; path = Views/Cells/Contacts/ContactsCell.xib; sourceTree = ""; }; - 50E18BB61B180F7D0076C3C6 /* SayHiView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SayHiView.swift; path = Views/SayHi/SayHiView.swift; sourceTree = ""; }; + 50E18BB61B180F7D0076C3C6 /* BottomButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BottomButtonView.swift; path = Views/SayHi/BottomButtonView.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1469,7 +1469,7 @@ 50E18BB81B180F8E0076C3C6 /* SayHi */ = { isa = PBXGroup; children = ( - 50E18BB61B180F7D0076C3C6 /* SayHiView.swift */, + 50E18BB61B180F7D0076C3C6 /* BottomButtonView.swift */, ); name = SayHi; sourceTree = ""; @@ -1929,7 +1929,7 @@ 505498621B12FB0E0037E3BD /* ConversationMessagePreviewNavigationControllerDelegate.swift in Sources */, 0A944C251AC8BB2F00037A06 /* YepStorageService.swift in Sources */, 505EC8171ADF8151001D27E0 /* SkillCategoryCell.swift in Sources */, - 50E18BB71B180F7D0076C3C6 /* SayHiView.swift in Sources */, + 50E18BB71B180F7D0076C3C6 /* BottomButtonView.swift in Sources */, 0A90187E1B01152800AE4B7F /* ProfileSocialAccountCell.swift in Sources */, 50894CF51AEA4A01000981AF /* SettingsUserCell.swift in Sources */, 5053AD5A1AF83B4200B3CBFA /* ChatLeftLocationCell.swift in Sources */, diff --git a/Yep/Base.lproj/Main.storyboard b/Yep/Base.lproj/Main.storyboard index 87b51548..1569f4d1 100644 --- a/Yep/Base.lproj/Main.storyboard +++ b/Yep/Base.lproj/Main.storyboard @@ -485,7 +485,7 @@ - + diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 6a4783de..dacea3d0 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -155,7 +155,7 @@ class ProfileViewController: UIViewController { sayHiView.hidden = true } else { - sayHiView.sayHiAction = { + sayHiView.tapAction = { self.sayHi() } @@ -175,7 +175,7 @@ class ProfileViewController: UIViewController { @IBOutlet weak var topShadowImageView: UIImageView! @IBOutlet weak var profileCollectionView: UICollectionView! - @IBOutlet weak var sayHiView: SayHiView! + @IBOutlet weak var sayHiView: BottomButtonView! var customNavigationBar: UINavigationBar! diff --git a/Yep/Views/SayHi/BottomButtonView.swift b/Yep/Views/SayHi/BottomButtonView.swift new file mode 100644 index 00000000..fdb527fb --- /dev/null +++ b/Yep/Views/SayHi/BottomButtonView.swift @@ -0,0 +1,77 @@ +// +// SayHiView.swift +// Yep +// +// Created by NIX on 15/5/29. +// Copyright (c) 2015年 Catch Inc. All rights reserved. +// + +import UIKit + +@IBDesignable +class BottomButtonView: UIView { + + @IBInspectable var topLineColor: UIColor = UIColor.lightGrayColor() + @IBInspectable var topLineWidth: CGFloat = 1 / UIScreen.mainScreen().scale + @IBInspectable var title: String = NSLocalizedString("Say Hi", comment: "") + + lazy var actionButton: UIButton = { + let button = UIButton() + button.titleLabel?.font = UIFont(name: "Helvetica-Regular", size: 14) + button.setTitle(self.title, forState: .Normal) + button.backgroundColor = UIColor.yepTintColor() + button.setTitleColor(UIColor.whiteColor(), forState: .Normal) + button.layer.cornerRadius = 5 + button.addTarget(self, action: "tryTap", forControlEvents: UIControlEvents.TouchUpInside) + return button + }() + + var tapAction: (() -> Void)? + + override func didMoveToSuperview() { + super.didMoveToSuperview() + + backgroundColor = UIColor.whiteColor() + + // Add actionButton + + self.addSubview(actionButton) + actionButton.setTranslatesAutoresizingMaskIntoConstraints(false) + + let actionButtonCenterXConstraint = NSLayoutConstraint(item: actionButton, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1.0, constant: 0) + + let actionButtonCenterYConstraint = NSLayoutConstraint(item: actionButton, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: 0) + + let actionButtonWidthConstraint = NSLayoutConstraint(item: actionButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 185) + + let actionButtonHeightConstraint = NSLayoutConstraint(item: actionButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 30) + + NSLayoutConstraint.activateConstraints([ + actionButtonCenterXConstraint, + actionButtonCenterYConstraint, + actionButtonWidthConstraint, + actionButtonHeightConstraint, + ]) + } + + // MARK: Actions + + func tryTap() { + tapAction?() + } + + // MARK: Draw + + override func drawRect(rect: CGRect) { + super.drawRect(rect) + + topLineColor.setStroke() + + let context = UIGraphicsGetCurrentContext() + + CGContextSetLineWidth(context, topLineWidth) + CGContextMoveToPoint(context, 0, 0) + CGContextAddLineToPoint(context, CGRectGetWidth(rect), 0) + CGContextStrokePath(context) + } +} diff --git a/Yep/Views/SayHi/SayHiView.swift b/Yep/Views/SayHi/SayHiView.swift deleted file mode 100644 index 8b31d0d4..00000000 --- a/Yep/Views/SayHi/SayHiView.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// SayHiView.swift -// Yep -// -// Created by NIX on 15/5/29. -// Copyright (c) 2015年 Catch Inc. All rights reserved. -// - -import UIKit - -@IBDesignable -class SayHiView: UIView { - - @IBInspectable var topLineColor: UIColor = UIColor.lightGrayColor() - @IBInspectable var topLineWidth: CGFloat = 1 / UIScreen.mainScreen().scale - - lazy var sayHiButton: UIButton = { - let button = UIButton() - button.titleLabel?.font = UIFont(name: "Helvetica-Regular", size: 14) - button.setTitle(NSLocalizedString("Say Hi", comment: ""), forState: .Normal) - button.backgroundColor = UIColor.yepTintColor() - button.setTitleColor(UIColor.whiteColor(), forState: .Normal) - button.layer.cornerRadius = 5 - button.addTarget(self, action: "trySayHi", forControlEvents: UIControlEvents.TouchUpInside) - return button - }() - - var sayHiAction: (() -> Void)? - - override func didMoveToSuperview() { - super.didMoveToSuperview() - - backgroundColor = UIColor.whiteColor() - - // Add sayHiButton - - self.addSubview(sayHiButton) - sayHiButton.setTranslatesAutoresizingMaskIntoConstraints(false) - - let sayHiButtonCenterXConstraint = NSLayoutConstraint(item: sayHiButton, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1.0, constant: 0) - - let sayHiButtonCenterYConstraint = NSLayoutConstraint(item: sayHiButton, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: 0) - - let sayHiButtonWidthConstraint = NSLayoutConstraint(item: sayHiButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 185) - - let sayHiButtonHeightConstraint = NSLayoutConstraint(item: sayHiButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 30) - - NSLayoutConstraint.activateConstraints([ - sayHiButtonCenterXConstraint, - sayHiButtonCenterYConstraint, - sayHiButtonWidthConstraint, - sayHiButtonHeightConstraint, - ]) - } - - // MARK: Actions - - func trySayHi() { - sayHiAction?() - } - - // MARK: Draw - - override func drawRect(rect: CGRect) { - super.drawRect(rect) - - topLineColor.setStroke() - - let context = UIGraphicsGetCurrentContext() - - CGContextSetLineWidth(context, topLineWidth) - CGContextMoveToPoint(context, 0, 0) - CGContextAddLineToPoint(context, CGRectGetWidth(rect), 0) - CGContextStrokePath(context) - } -}