Last active
March 1, 2017 02:49
-
-
Save davidortinau/2356fcfd123f827ab23c8522b0a72ee2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In your Forms shared code | |
using System; | |
using Xamarin.Forms; | |
namespace FormsPlayground | |
{ | |
public class DisabledTitleColorEffect : RoutingEffect | |
{ | |
string _disabledColor; | |
public string DisabledColor | |
{ | |
get | |
{ | |
return _disabledColor; | |
} | |
set | |
{ | |
_disabledColor = value; | |
} | |
} | |
public DisabledTitleColorEffect() : base ("FormsPlayground.DisabledTitleColorEffect") | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In your iOS project | |
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using UIKit; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Platform.iOS; | |
[assembly:ResolutionGroupName ("FormsPlayground")] | |
[assembly: ExportEffect (typeof (FormsPlayground.iOS.DisabledTitleColorEffect), "DisabledTitleColorEffect")] | |
namespace FormsPlayground.iOS | |
{ | |
public class DisabledTitleColorEffect : PlatformEffect | |
{ | |
protected override void OnAttached () | |
{ | |
try { | |
var effect = (FormsPlayground.DisabledTitleColorEffect)Element.Effects.FirstOrDefault (e => e is FormsPlayground.DisabledTitleColorEffect); | |
var btn = (UIButton)Control; | |
btn.SetTitleColor(Color.FromHex(effect.DisabledColor).ToUIColor(), UIControlState.Disabled); | |
} catch (Exception ex) { | |
Debug.WriteLine ("Cannot set property on attached control. Error: ", ex.Message); | |
} | |
} | |
protected override void OnDetached () | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:local="clr-namespace:FormsPlayground" x:Class="FormsPlayground.FormsPlaygroundPage"> | |
<!-- other things --> | |
<Button x:Name="btnForgotPassword" | |
BackgroundColor="Transparent" Text="other text" TextColor="#80868C" Clicked="Handle_Clicked" | |
VerticalOptions="Start"> | |
<Button.Effects> | |
<local:DisabledTitleColorEffect DisabledColor="#CC0000"/> | |
</Button.Effects> | |
</Button> | |
<!-- other things --> | |
</ContentPage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was actually very helpful, thanks very much! :)