Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Added button labels #1146

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ public ViewController(IntPtr handle)
public override void ViewDidLoad()
{
base.ViewDidLoad();


var font = UIFont.SystemFontOfSize(12);

LiquidFloatingCell.DefaultTitleColor = UIColor.White;

var cells = new List<LiquidFloatingCell>
{
new LiquidFloatingCell(UIImage.FromBundle("ic_cloud")),
new LiquidFloatingCell(UIImage.FromBundle("ic_system")),
new LiquidFloatingCell(UIImage.FromBundle("ic_place")),
new LiquidFloatingCell(UIImage.FromBundle("ic_cloud"), "cloud")
.WithTitleFont(font)
.WithTitleColor(UIColor.Green),
new LiquidFloatingCell(UIImage.FromBundle("ic_system"), "system"),
new LiquidFloatingCell(UIImage.FromBundle("ic_place"), "place")
};

topLeftButton.Image = UIImage.FromBundle("ic_art");
Expand All @@ -36,12 +42,14 @@ public override void ViewDidLoad()
{
topLeftButton.Close();
};

topLeftButton.TitlePosition = TitlePositions.Right;

bottomRightButton.Cells = cells;
bottomRightButton.CellSelected += delegate
{
bottomRightButton.Close();
};
bottomRightButton.TitlePosition = TitlePositions.Left;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class LiquidFloatingActionButton : UIControl
private CircleLiquidBaseView baseView = new CircleLiquidBaseView();
private UIView liquidView = new UIView();

public TitlePositions TitlePosition { get; set; }

public LiquidFloatingActionButton()
{
Setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Compile Include="CoreGraphicsExtensions.cs" />
<Compile Include="SimpleCircleLiquidEngine.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TitlePositions.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ public class LiquidFloatingCell : LiquittableCircle
private UIImageView imageView;

private UIColor originalColor = UIColor.Clear;
private UIFont _titleFont;
private UIColor _titleColor;

public static UIColor DefaultTitleColor { get; set; } = UIColor.LabelColor;

public static UIFont DefaultTitleFont { get; set; } = UIFont.SystemFontOfSize(UIFont.SystemFontSize);

public UIFont TitleFont { get => _titleFont; }

public UIColor TitleColor { get => _titleColor; }

public UIView View { get; private set; }

public UILabel Label { get; private set; }

public LiquidFloatingActionButton ActionButton
{
get
Expand All @@ -42,7 +54,7 @@ public LiquidFloatingActionButton ActionButton
internal set { actionButton.SetTarget(value); }
}

public bool Responsible { get; set; }
public bool Responsible { get; set; }

public override void LayoutSubviews()
{
Expand All @@ -56,11 +68,38 @@ public override void LayoutSubviews()
}
}

public override void WillMoveToSuperview(UIView newsuper)
{
base.WillMoveToSuperview(newsuper);

Label.Font = _titleFont ?? DefaultTitleFont;
Label.TextColor = _titleColor ?? DefaultTitleColor;

if (Label != null)
{
var size = (Label.Text + " ").StringSize(Label.Font);
var actionButton = ActionButton;
if (actionButton != null)
{
if (actionButton.TitlePosition == TitlePositions.Left)
Label.Frame = new CGRect(-size.Width, (Frame.Height - size.Height) / 2, size.Width, size.Height);
else
Label.Frame = new CGRect(Frame.Width + (" ").StringSize(Label.Font).Width, (Frame.Height - size.Height) / 2, size.Width, size.Height);
}
}
}

public LiquidFloatingCell(UIImage icon)
{
Setup(icon);
}

public LiquidFloatingCell(UIImage icon, string title)
{
Setup(icon);
SetupLabel(title);
}

public LiquidFloatingCell(UIImage icon, nfloat imageRatio)
{
this.imageRatio = imageRatio;
Expand All @@ -72,6 +111,12 @@ public LiquidFloatingCell(UIView view)
SetupView(view);
}

private void SetupLabel(string title)
{
Label = new UILabel() { Text = title, Alpha = 0 };
AddSubview(Label);
}

private void Setup(UIImage image, UIColor tintColor = null)
{
imageView = new UIImageView();
Expand Down Expand Up @@ -129,5 +174,18 @@ public override void TouchesEnded(NSSet touches, UIEvent evt)
button.OnCellSelected(this);
}
}

public LiquidFloatingCell WithTitleFont(UIFont font)
{
_titleFont = font;
return this;
}

public LiquidFloatingCell WithTitleColor(UIColor color)
{
_titleColor = color;

return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace AnimatedButtons
{
public enum TitlePositions
{
Left,
Right
}
}