Skip to content

Commit

Permalink
Merge pull request #7 from sescalada/textcolor
Browse files Browse the repository at this point in the history
Added TextColor and FontFamily properties to customize badge label
  • Loading branch information
SuavePirate authored Jun 27, 2018
2 parents 25353e0 + bd2406a commit d184d2e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Example/BadgeViewExample/BadgePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<ContentPage.Content>
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="Center">
<Label HorizontalTextAlignment="Center" Text="Look at me!" />
<badge:BadgeView Text="3" BadgeColor="Green" VerticalOptions="Center" HorizontalOptions="End" />
<badge:BadgeView Text="3" BadgeColor="Green" TextColor="Yellow" VerticalOptions="Center" HorizontalOptions="End">
<badge:BadgeView.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="sans-serif-thin" />
<On Platform="iOS" Value="Courier-Bold" />
</OnPlatform>
</badge:BadgeView.FontFamily>
</badge:BadgeView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
40 changes: 40 additions & 0 deletions src/BadgeView.Shared/BadgeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ public partial class BadgeView : Grid
view.BadgeLabel.Text = (string)newVal;
});

public static BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(BadgeView), Color.White, propertyChanged: (bindable, oldVal, newVal) =>
{
var view = (BadgeView)bindable;
view.BadgeLabel.TextColor = (Color)newVal;
});

public static BindableProperty FontFamilyProperty = BindableProperty.Create("FontFamily", typeof(string), typeof(BadgeView), Label.FontFamilyProperty.DefaultValue, propertyChanged: (bindable, oldVal, newVal) =>
{
var view = (BadgeView)bindable;
view.BadgeLabel.FontFamily = (string)newVal;
});

public static BindableProperty BadgeColorProperty = BindableProperty.Create("BadgeColor", typeof(Color), typeof(BadgeView), Color.Blue, propertyChanged: (bindable, oldVal, newVal) =>
{
var view = (BadgeView)bindable;
Expand All @@ -29,6 +41,31 @@ public string Text
SetValue(TextProperty, value);
}
}

public Color TextColor
{
get
{
return (Color)GetValue(TextColorProperty);
}
set
{
SetValue(TextColorProperty, value);
}
}

public string FontFamily
{
get
{
return (string)GetValue(FontFamilyProperty);
}
set
{
SetValue(FontFamilyProperty, value);
}
}

public Color BadgeColor
{
get
Expand All @@ -40,10 +77,13 @@ public Color BadgeColor
SetValue(BadgeColorProperty, value);
}
}

public BadgeView()
{
InitializeComponent();
BadgeLabel.Text = Text;
BadgeLabel.TextColor = TextColor;
BadgeLabel.FontFamily = FontFamily;
BadgeCircle.BackgroundColor = BadgeColor;
}
}
Expand Down

0 comments on commit d184d2e

Please sign in to comment.