зеркало из https://github.com/xamarin/ios-samples.git
[Chat] implement chat input tool bar view
Xamarin.iOS 8.10.0.255
This commit is contained in:
Родитель
7118060add
Коммит
146d4338db
|
@ -127,10 +127,12 @@
|
|||
<DependentUpon>OutgoingCell.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Cells\BubbleCell.cs" />
|
||||
<Compile Include="ChatInput\ChatInputView.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Cells\" />
|
||||
<Folder Include="Resources\Images.xcassets\MessageBubble.imageset\" />
|
||||
<Folder Include="ChatInput\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
|
||||
using UIKit;
|
||||
using Foundation;
|
||||
|
||||
namespace Chat
|
||||
{
|
||||
public partial class ChatInputView : UIView
|
||||
{
|
||||
public UITextView TextView { get; private set; }
|
||||
public UIButton SendButton { get; private set; }
|
||||
|
||||
public ChatInputView()
|
||||
{
|
||||
TextView = new UITextView ();
|
||||
TextView.Layer.BorderColor = UIColor.FromRGB (200, 200, 205).CGColor;
|
||||
TextView.Layer.BorderWidth = (float)0.5;
|
||||
TextView.Layer.CornerRadius = 5;
|
||||
TextView.BackgroundColor = UIColor.FromWhiteAlpha (250, 1);
|
||||
TextView.TranslatesAutoresizingMaskIntoConstraints = false;
|
||||
|
||||
SendButton = new UIButton ();
|
||||
SendButton.SetTitle ("Send", UIControlState.Normal);
|
||||
SendButton.Font = UIFont.SystemFontOfSize (15, UIFontWeight.Bold);
|
||||
SendButton.TranslatesAutoresizingMaskIntoConstraints = false;
|
||||
SendButton.SetTitleColor (UIColor.FromRGB (142, 142, 147), UIControlState.Disabled);
|
||||
SendButton.SetTitleColor (UIColor.FromRGB (1, 122, 255), UIControlState.Normal);
|
||||
|
||||
AddSubviews (TextView, SendButton);
|
||||
|
||||
var c1 = NSLayoutConstraint.FromVisualFormat ("H:|-[input]-[button]-|",
|
||||
NSLayoutFormatOptions.DirectionLeadingToTrailing,
|
||||
"input", TextView,
|
||||
"button", SendButton
|
||||
);
|
||||
var c2 = NSLayoutConstraint.FromVisualFormat ("V:|-[input]-|",
|
||||
NSLayoutFormatOptions.DirectionLeadingToTrailing,
|
||||
"input", TextView
|
||||
);
|
||||
var c3 = NSLayoutConstraint.FromVisualFormat ("V:[button]-|",
|
||||
NSLayoutFormatOptions.DirectionLeadingToTrailing,
|
||||
"button", SendButton
|
||||
);
|
||||
AddConstraints (c1);
|
||||
AddConstraints (c2);
|
||||
AddConstraints (c3);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,19 @@ namespace Chat
|
|||
// We need dummy input for keeping keyboard visible during showing menu
|
||||
DummyInput hiddenInput;
|
||||
|
||||
ChatInputView chatInputView;
|
||||
UIButton SendButton {
|
||||
get {
|
||||
return chatInputView.SendButton;
|
||||
}
|
||||
}
|
||||
|
||||
UITextView TextView {
|
||||
get {
|
||||
return chatInputView.TextView;
|
||||
}
|
||||
}
|
||||
|
||||
NSIndexPath LastIndexPath {
|
||||
get {
|
||||
return NSIndexPath.FromRowSection (messages.Count - 1, 0);
|
||||
|
@ -52,15 +65,21 @@ namespace Chat
|
|||
};
|
||||
View.AddSubview (hiddenInput);
|
||||
|
||||
chatSrc = new ChatSource (messages, ShowMenu);
|
||||
chatInputView = new ChatInputView ();
|
||||
|
||||
SendButton.TouchUpInside += OnSendClicked;
|
||||
|
||||
TextView.Changed += OnTextChanged;
|
||||
TextView.Layer.BorderColor = UIColor.FromRGB (200, 200, 205).CGColor;
|
||||
TextView.Layer.BorderWidth = (float)0.5;
|
||||
TextView.Layer.CornerRadius = 5;
|
||||
TextView.BackgroundColor = UIColor.FromWhiteAlpha (250, 1);
|
||||
|
||||
chatSrc = new ChatSource (messages, ShowMenu);
|
||||
TableView.Source = chatSrc;
|
||||
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
|
||||
|
||||
UpdateToolbar ();
|
||||
}
|
||||
|
||||
public override void ViewWillAppear (bool animated)
|
||||
|
@ -75,6 +94,23 @@ namespace Chat
|
|||
UpdateButtonState ();
|
||||
}
|
||||
|
||||
void UpdateToolbar ()
|
||||
{
|
||||
chatInputView.TranslatesAutoresizingMaskIntoConstraints = false;
|
||||
Chat.AddSubview (chatInputView);
|
||||
|
||||
var c1 = NSLayoutConstraint.FromVisualFormat ("H:|[chat]|",
|
||||
NSLayoutFormatOptions.DirectionLeadingToTrailing,
|
||||
"chat", chatInputView
|
||||
);
|
||||
var c2 = NSLayoutConstraint.FromVisualFormat ("V:|[chat]|",
|
||||
NSLayoutFormatOptions.DirectionLeadingToTrailing,
|
||||
"chat", chatInputView
|
||||
);
|
||||
Chat.AddConstraints (c1);
|
||||
Chat.AddConstraints (c2);
|
||||
}
|
||||
|
||||
void KeyboardWillShowHandler (object sender, UIKeyboardEventArgs e)
|
||||
{
|
||||
UpdateButtomLayoutConstraint (e);
|
||||
|
|
|
@ -18,14 +18,8 @@ namespace Chat
|
|||
[Outlet]
|
||||
UIKit.UIToolbar Chat { get; set; }
|
||||
|
||||
[Outlet]
|
||||
UIKit.UIButton SendButton { get; set; }
|
||||
|
||||
[Outlet]
|
||||
UIKit.UITableView TableView { get; set; }
|
||||
|
||||
[Outlet]
|
||||
UIKit.UITextView TextView { get; set; }
|
||||
|
||||
void ReleaseDesignerOutlets ()
|
||||
{
|
||||
|
@ -34,25 +28,15 @@ namespace Chat
|
|||
BottomConstraint = null;
|
||||
}
|
||||
|
||||
if (SendButton != null) {
|
||||
SendButton.Dispose ();
|
||||
SendButton = null;
|
||||
if (Chat != null) {
|
||||
Chat.Dispose ();
|
||||
Chat = null;
|
||||
}
|
||||
|
||||
if (TableView != null) {
|
||||
TableView.Dispose ();
|
||||
TableView = null;
|
||||
}
|
||||
|
||||
if (TextView != null) {
|
||||
TextView.Dispose ();
|
||||
TextView = null;
|
||||
}
|
||||
|
||||
if (Chat != null) {
|
||||
Chat.Dispose ();
|
||||
Chat = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,40 +90,7 @@
|
|||
</tableView>
|
||||
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="I0R-VL-Zim">
|
||||
<rect key="frame" x="0.0" y="524" width="320" height="44"/>
|
||||
<items>
|
||||
<barButtonItem style="plain" id="sVc-WU-d6Y">
|
||||
<view key="customView" contentMode="scaleToFill" id="KaN-id-a6M">
|
||||
<rect key="frame" x="0.0" y="0.0" width="240" height="33"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="d3L-af-1Fu">
|
||||
<rect key="frame" x="0.0" y="2" width="240" height="29"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
</textView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="d3L-af-1Fu" secondAttribute="trailing" id="8xq-dt-7w6"/>
|
||||
<constraint firstItem="d3L-af-1Fu" firstAttribute="top" secondItem="KaN-id-a6M" secondAttribute="top" constant="2" id="KWC-Bw-ObR"/>
|
||||
<constraint firstItem="d3L-af-1Fu" firstAttribute="leading" secondItem="KaN-id-a6M" secondAttribute="leading" id="LTD-zz-ewN"/>
|
||||
<constraint firstAttribute="bottom" secondItem="d3L-af-1Fu" secondAttribute="bottom" constant="2" id="ocY-xX-anO"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</barButtonItem>
|
||||
<barButtonItem style="plain" id="PNb-d5-2zi">
|
||||
<button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="ql2-lV-URf">
|
||||
<rect key="frame" x="-23" y="-15" width="46" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
|
||||
<state key="normal" title="Send">
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
</button>
|
||||
</barButtonItem>
|
||||
</items>
|
||||
<items/>
|
||||
</toolbar>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
|
@ -140,9 +107,7 @@
|
|||
<connections>
|
||||
<outlet property="BottomConstraint" destination="h8p-2S-2Fa" id="UZF-Fp-rt0"/>
|
||||
<outlet property="Chat" destination="I0R-VL-Zim" id="8Fp-6C-mzu"/>
|
||||
<outlet property="SendButton" destination="ql2-lV-URf" id="VeN-LP-NTh"/>
|
||||
<outlet property="TableView" destination="0ka-sN-sOO" id="uxW-0d-AwN"/>
|
||||
<outlet property="TextView" destination="d3L-af-1Fu" id="rRt-bN-oNC"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
|
||||
|
|
Загрузка…
Ссылка в новой задаче