diff --git a/Rouble/IOs/MainController.cs b/Rouble/IOs/MainController.cs index 57135db..8a7941c 100644 --- a/Rouble/IOs/MainController.cs +++ b/Rouble/IOs/MainController.cs @@ -1,18 +1,24 @@ using System; +using System.Drawing; using MonoTouch.UIKit; -using System.Drawing; +using MonoTouch.Foundation; + namespace Rouble { public class MainController : UIViewController { - private const string Text = "Цена: 100 {0}"; + private const string Text = "Цена: 100 "; private UILabel _label1; private UILabel _label2; private UILabel _label3; + private UIFont _font1; + private UIFont _font2; + private UIFont _font3; + private UIFont _roubleFont; public MainController () { @@ -23,37 +29,57 @@ namespace Rouble { base.ViewDidLoad (); + InitFonts (); View.BackgroundColor = UIColor.White; _label1 = new UILabel (); - _label1.Text = Text; + SetText (_label1, _font1, RoubleType.Regular); View.AddSubview (_label1); _label2 = new UILabel (); - _label2.Text = Text; + SetText (_label2, _font2, RoubleType.Medium); View.AddSubview (_label2); _label3 = new UILabel (); - _label3.Text = Text; + SetText (_label3, _font3, RoubleType.Bold); View.AddSubview (_label3); } + private void InitFonts() + { + _font1 = UIFont.FromName ("HelveticaNeue", 18f); + _font2 = UIFont.FromName ("HelveticaNeue-Medium", 18f); + _font3 = UIFont.FromName ("HelveticaNeue-Bold", 18f); + _roubleFont = UIFont.FromName("Ruble", 18f); + } + public override void ViewDidLayoutSubviews() { base.ViewWillLayoutSubviews (); _label1.SizeToFit (); _label1.Center = View.Center; + MoveY (_label1, -50f); _label2.SizeToFit (); _label2.Center = View.Center; - MoveY (_label2, -50f); _label3.SizeToFit (); _label3.Center = View.Center; MoveY (_label3, 50f); } + private void SetText(UILabel label, UIFont font, RoubleType type) + { + char roubleSym = Roubles.GetRoubleSymbFor (type); + + NSMutableAttributedString attrString = new NSMutableAttributedString(); + attrString.Append(new NSAttributedString(Text, font: font, foregroundColor: UIColor.Black)); + attrString.Append(new NSAttributedString(roubleSym.ToString(), font: _roubleFont, foregroundColor: UIColor.Black)); + + label.AttributedText = attrString; + } + private void MoveY(UIView view, float dy) { RectangleF frame = view.Frame; diff --git a/Rouble/IOs/Rouble.csproj b/Rouble/IOs/Rouble.csproj index 5590255..bb938ab 100644 --- a/Rouble/IOs/Rouble.csproj +++ b/Rouble/IOs/Rouble.csproj @@ -98,6 +98,12 @@ + + Rouble.cs + + + RoubleType.cs + diff --git a/Rouble/Shared/Rouble.cs b/Rouble/Shared/Rouble.cs new file mode 100644 index 0000000..2561def --- /dev/null +++ b/Rouble/Shared/Rouble.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; + +namespace Rouble +{ + public static class Roubles + { + private static readonly Dictionary _roubleSymbols; + + public static char RegularSymbol + { + get { return GetRoubleSymbFor(RoubleType.Regular); } + } + + public static char MediumSymbol + { + get { return GetRoubleSymbFor(RoubleType.Medium); } + } + + public static char BoldSympbol + { + get { return GetRoubleSymbFor(RoubleType.Bold); } + } + + static Roubles() + { + _roubleSymbols = new Dictionary(3) + { + { RoubleType.Regular, 'r' }, + { RoubleType.Medium, 'm' }, + { RoubleType.Bold, 'b' }, + }; + } + + public static char GetRoubleSymbFor(RoubleType type) + { + return _roubleSymbols[type]; + } + } +} diff --git a/Rouble/Shared/RoubleType.cs b/Rouble/Shared/RoubleType.cs new file mode 100644 index 0000000..0a0e290 --- /dev/null +++ b/Rouble/Shared/RoubleType.cs @@ -0,0 +1,11 @@ +using System; + +namespace Rouble +{ + public enum RoubleType + { + Regular, + Medium, + Bold + } +}