Skip to content

Commit

Permalink
Add designer support for FloatLabeledTextField
Browse files Browse the repository at this point in the history
  • Loading branch information
gshackles committed Feb 12, 2017
1 parent c3f11eb commit 183c5a1
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 36 deletions.
37 changes: 21 additions & 16 deletions samples/FLEDemo.iOS/DialogDemoViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@

namespace FLEDemo.iOS
{
public class DialogDemoViewController : DialogViewController
{
public DialogDemoViewController()
: base(UITableViewStyle.Grouped, null, true)
{
Root = new RootElement("Dialog")
{
new Section
{
new FloatLabeledEntryElement("First Name"),
new FloatLabeledEntryElement("Password", isPassword: true),
new FloatLabeledEntryElement("Prefilled value", value: "Foo bar baz")
}
};
}
}
public class DialogDemoViewController : DialogViewController
{
public DialogDemoViewController()
: base(UITableViewStyle.Grouped, null, true)
{
Root = new RootElement("Dialog")
{
new Section
{
new FloatLabeledEntryElement("First Name"),
new FloatLabeledEntryElement("Password", isPassword: true),
new FloatLabeledEntryElement("Prefilled value", value: "Foo bar baz")
}
};

NavigationItem.RightBarButtonItem = new UIBarButtonItem(
"Storyboard Demo",
UIBarButtonItemStyle.Plain,
(s, a) => NavigationController.PushViewController(UIStoryboard.FromName("Storyboard", null).InstantiateViewController("StoryboardViewController"), true));
}
}
}
5 changes: 5 additions & 0 deletions samples/FLEDemo.iOS/FLEDemo.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Resources\LaunchScreen.xib" />
<InterfaceDefinition Include="Storyboard.storyboard" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
Expand All @@ -86,6 +87,10 @@
<Compile Include="AppDelegate.cs" />
<Compile Include="MainViewController.cs" />
<Compile Include="DialogDemoViewController.cs" />
<Compile Include="StoryboardViewController.cs" />
<Compile Include="StoryboardViewController.designer.cs">
<DependentUpon>StoryboardViewController.cs</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
78 changes: 78 additions & 0 deletions samples/FLEDemo.iOS/Storyboard.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="5">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<scene sceneID="4">
<objects>
<viewController id="5" sceneMemberID="viewController" customClass="StoryboardViewController" storyboardIdentifier="StoryboardViewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="2"/>
<viewControllerLayoutGuide type="bottom" id="3"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="6">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" id="11" customClass="Float Labeled Text Field" translatesAutoresizingMaskIntoConstraints="NO" placeholder="First Name" text="Greg">
<rect key="frame" x="15" y="50" width="570" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="Floating Label Text Color">
<color key="value" colorSpace="calibratedRGB" red="0" green="1" blue="0" alpha="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="Floating Label Active Text Color">
<color key="value" colorSpace="calibratedRGB" red="0.49803921568627452" green="0" blue="0.49803921568627452" alpha="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="FloatingLabelTextColor">
<color key="value" colorSpace="calibratedRGB" red="0.49803921568627452" green="0" blue="0.49803921568627452" alpha="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="FloatingLabelActiveTextColor">
<color key="value" colorSpace="calibratedRGB" red="1" green="0" blue="0" alpha="1"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<constraints>
<constraint id="31" firstItem="11" firstAttribute="height" constant="44"/>
</constraints>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" id="20" customClass="Float Labeled Text Field" translatesAutoresizingMaskIntoConstraints="NO" placeholder="Last Name">
<rect key="frame" x="15" y="109" width="570" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="Floating Label Text Color">
<color key="value" colorSpace="calibratedRGB" red="0" green="1" blue="0" alpha="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="Floating Label Active Text Color">
<color key="value" colorSpace="calibratedRGB" red="0.49803921568627452" green="0" blue="0.49803921568627452" alpha="1"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<constraints>
<constraint id="21" firstItem="20" firstAttribute="height" constant="44"/>
</constraints>
</textField>
</subviews>
<constraints>
<constraint id="28" firstItem="11" firstAttribute="top" secondItem="2" secondAttribute="bottom" constant="30"/>
<constraint id="29" firstItem="11" firstAttribute="leading" secondItem="6" secondAttribute="leading" constant="15"/>
<constraint id="30" firstItem="6" firstAttribute="trailing" secondItem="11" secondAttribute="trailing" constant="15"/>
<constraint id="32" firstItem="20" firstAttribute="leading" secondItem="11" secondAttribute="leading"/>
<constraint id="33" firstItem="11" firstAttribute="trailing" secondItem="20" secondAttribute="trailing"/>
<constraint id="36" firstItem="20" firstAttribute="top" secondItem="11" secondAttribute="bottom" constant="15"/>
</constraints>
</view>
<connections>
<outlet property="FirstName" destination="11" id="name-outlet-11"/>
<outlet property="LastName" destination="20" id="name-outlet-20"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="128" y="-50"/>
</scene>
</scenes>
</document>
13 changes: 13 additions & 0 deletions samples/FLEDemo.iOS/StoryboardViewController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Foundation;
using System;
using UIKit;

namespace FLEDemo.iOS
{
public partial class StoryboardViewController : UIViewController
{
public StoryboardViewController (IntPtr handle) : base (handle)
{
}
}
}
38 changes: 38 additions & 0 deletions samples/FLEDemo.iOS/StoryboardViewController.designer.cs

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

58 changes: 38 additions & 20 deletions src/iOS/FloatLabeledEntry.iOS/FloatLabeledTextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,53 @@
using System;
using UIKit;
using CoreGraphics;
using Foundation;
using System.ComponentModel;

namespace FloatLabeledEntry
{
[Register("Float Labeled Text Field"), DesignTimeVisible(true)]
public class FloatLabeledTextField : UITextField
{
private readonly UILabel _floatingLabel;
private UILabel _floatingLabel;

public UIColor FloatingLabelTextColor { get; set; }
public UIColor FloatingLabelActiveTextColor { get; set; }
public UIFont FloatingLabelFont
{
get { return _floatingLabel.Font; }
set { _floatingLabel.Font = value; }
}
[DisplayName("Label Color"), Export("FloatingLabelTextColor"), Browsable(true)]
public UIColor FloatingLabelTextColor { get; set; } = UIColor.Gray;

public FloatLabeledTextField(CGRect frame)
: base(frame)
{
_floatingLabel = new UILabel
{
Alpha = 0.0f
};
[DisplayName("Label Active Color"), Export("FloatingLabelActiveTextColor"), Browsable(true)]
public UIColor FloatingLabelActiveTextColor { get; set; } = UIColor.Blue;

AddSubview(_floatingLabel);
public UIFont FloatingLabelFont
{
get { return _floatingLabel.Font; }
set { _floatingLabel.Font = value; }
}

FloatingLabelTextColor = UIColor.Gray;
FloatingLabelActiveTextColor = UIColor.Blue;
FloatingLabelFont = UIFont.BoldSystemFontOfSize(12);
}
public FloatLabeledTextField(CGRect frame)
: base(frame)
{
InitializeLabel();
}

public FloatLabeledTextField(IntPtr handle)
: base(handle)
{
}

public override void AwakeFromNib() => InitializeLabel();

private void InitializeLabel()
{
_floatingLabel = new UILabel
{
Alpha = 0.0f,
Font = UIFont.BoldSystemFontOfSize(12)
};

AddSubview(_floatingLabel);

Placeholder = Placeholder; // sets up label frame
}

public override string Placeholder
{
Expand Down
20 changes: 20 additions & 0 deletions src/iOS/FloatLabeledEntry.iOS/FloatLabeledTextField.designer.cs

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

0 comments on commit 183c5a1

Please sign in to comment.