mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-13 23:07:37 +10:00
add ConversationTitleView for ConversationViewController
This commit is contained in:
@@ -139,6 +139,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 */; };
|
||||
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 */; };
|
||||
50EB8CC01AE89ED8001AC1EE /* ChatLeftVideoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50EB8CBE1AE89ED8001AC1EE /* ChatLeftVideoCell.xib */; };
|
||||
@@ -299,6 +300,7 @@
|
||||
50E114F81ABC137A00F13000 /* YepServiceSync.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepServiceSync.swift; path = Services/YepServiceSync.swift; sourceTree = "<group>"; };
|
||||
50E114FA1ABC549300F13000 /* ContactsCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactsCell.swift; path = Views/Cells/Contacts/ContactsCell.swift; sourceTree = "<group>"; };
|
||||
50E114FB1ABC549300F13000 /* ContactsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ContactsCell.xib; path = Views/Cells/Contacts/ContactsCell.xib; sourceTree = "<group>"; };
|
||||
50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = "<group>"; };
|
||||
50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = "<group>"; };
|
||||
50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = "<group>"; };
|
||||
50EB8CBE1AE89ED8001AC1EE /* ChatLeftVideoCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ChatLeftVideoCell.xib; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.xib; sourceTree = "<group>"; };
|
||||
@@ -527,6 +529,7 @@
|
||||
503315A11AC126140008A209 /* MessageToolbar */,
|
||||
508D16BE1ADCAF0900270E3F /* PullToRefresh */,
|
||||
50EB8CCC1AEA1AC5001AC1EE /* Media */,
|
||||
50E61CEC1AF1F6A600908A9D /* ConversationTitle */,
|
||||
);
|
||||
name = Views;
|
||||
sourceTree = "<group>";
|
||||
@@ -968,6 +971,14 @@
|
||||
name = Contacts;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
50E61CEC1AF1F6A600908A9D /* ConversationTitle */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */,
|
||||
);
|
||||
name = ConversationTitle;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
50EB8CC11AE89EDE001AC1EE /* ChatLeftVideo */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -1247,6 +1258,7 @@
|
||||
506923141ADE025F00D27574 /* YepRefreshView.swift in Sources */,
|
||||
503CAB431AC00CB100DFE830 /* ConversationViewController.swift in Sources */,
|
||||
50553F931ADBA50600F80B59 /* NSDate+Yep.swift in Sources */,
|
||||
50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */,
|
||||
5023DE331AB688F600B3EE96 /* UIColor+Yep.swift in Sources */,
|
||||
503315971AC1017E0008A209 /* ChatLeftTextCell.swift in Sources */,
|
||||
0A8F54B11AB67D11004AD60E /* AppDelegate.swift in Sources */,
|
||||
|
||||
@@ -201,6 +201,21 @@ func groupWithGroupID(groupID: String) -> Group? {
|
||||
return Group.objectsWithPredicate(predicate).firstObject() as? Group
|
||||
}
|
||||
|
||||
func nameOfConversation(conversation: Conversation) -> String? {
|
||||
if conversation.type == ConversationType.OneToOne.rawValue {
|
||||
if let withFriend = conversation.withFriend {
|
||||
return withFriend.nickname
|
||||
}
|
||||
|
||||
} else if conversation.type == ConversationType.Group.rawValue {
|
||||
if let withGroup = conversation.withGroup {
|
||||
return withGroup.groupName
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func avatarWithAvatarURLString(avatarURLString: String) -> Avatar? {
|
||||
let predicate = NSPredicate(format: "avatarURLString = %@", avatarURLString)
|
||||
return Avatar.objectsWithPredicate(predicate).firstObject() as? Avatar
|
||||
|
||||
@@ -60,6 +60,13 @@ class ConversationViewController: UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
lazy var titleView: ConversationTitleView = {
|
||||
let titleView = ConversationTitleView(frame: CGRect(origin: CGPointZero, size: CGSize(width: 150, height: 44)))
|
||||
titleView.nameLabel.text = nameOfConversation(self.conversation)
|
||||
titleView.stateInfoLabel.text = "Hello world"
|
||||
return titleView
|
||||
}()
|
||||
|
||||
lazy var pullToRefreshView = PullToRefreshView()
|
||||
|
||||
@IBOutlet weak var conversationCollectionView: UICollectionView!
|
||||
@@ -148,6 +155,7 @@ class ConversationViewController: UIViewController {
|
||||
displayedMessagesRange = NSRange(location: 0, length: Int(messages.count))
|
||||
}
|
||||
|
||||
navigationItem.titleView = titleView
|
||||
|
||||
let undoBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Undo, target: self, action: "undoMessageSend")
|
||||
navigationItem.rightBarButtonItem = undoBarButtonItem
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// ConversationTitleView.swift
|
||||
// Yep
|
||||
//
|
||||
// Created by NIX on 15/4/30.
|
||||
// Copyright (c) 2015年 Catch Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class ConversationTitleView: UIView {
|
||||
|
||||
lazy var nameLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textAlignment = .Center
|
||||
label.font = UIFont(name: "Helvetica-Bold", size: 15)!
|
||||
return label
|
||||
}()
|
||||
|
||||
lazy var stateInfoLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textAlignment = .Center
|
||||
label.font = UIFont(name: "Helvetica-Light", size: 10)!
|
||||
label.textColor = UIColor.grayColor()
|
||||
return label
|
||||
}()
|
||||
|
||||
override func didMoveToSuperview() {
|
||||
super.didMoveToSuperview()
|
||||
|
||||
makeUI()
|
||||
}
|
||||
|
||||
func makeUI() {
|
||||
addSubview(nameLabel)
|
||||
addSubview(stateInfoLabel)
|
||||
|
||||
let helperView = UIView()
|
||||
|
||||
addSubview(helperView)
|
||||
|
||||
nameLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
|
||||
stateInfoLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
|
||||
|
||||
helperView.setTranslatesAutoresizingMaskIntoConstraints(false)
|
||||
|
||||
let viewsDictionary = [
|
||||
"nameLabel": nameLabel,
|
||||
"stateInfoLabel": stateInfoLabel,
|
||||
"helperView": helperView,
|
||||
]
|
||||
|
||||
let helperViewCenterX = NSLayoutConstraint(item: helperView, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0)
|
||||
let helperViewCenterY = NSLayoutConstraint(item: helperView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0)
|
||||
let helperViewTop = NSLayoutConstraint(item: helperView, attribute: .Top, relatedBy: .Equal, toItem: nameLabel, attribute: .Top, multiplier: 1, constant: 0)
|
||||
let helperViewBottom = NSLayoutConstraint(item: helperView, attribute: .Bottom, relatedBy: .Equal, toItem: stateInfoLabel, attribute: .Bottom, multiplier: 1, constant: 0)
|
||||
|
||||
NSLayoutConstraint.activateConstraints([helperViewCenterX, helperViewCenterY, helperViewTop, helperViewBottom])
|
||||
|
||||
let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:[nameLabel(24)][stateInfoLabel(12)]", options: .AlignAllCenterX | .AlignAllLeading | .AlignAllTrailing, metrics: nil, views: viewsDictionary)
|
||||
|
||||
let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[nameLabel]|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary)
|
||||
|
||||
NSLayoutConstraint.activateConstraints(constraintsV)
|
||||
NSLayoutConstraint.activateConstraints(constraintsH)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user