Skip to content

Commit

Permalink
Fix for a multiline label showing up in a TINY font.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicwise committed Apr 20, 2015
1 parent 6e9cdb4 commit b16535f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 81 deletions.
37 changes: 17 additions & 20 deletions BTProgressHUD.sln
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
# Visual Studio 2012
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BTProgressHUD-Classic", "BTProgressHUD\BTProgressHUD-Classic.csproj", "{173ADCB0-C964-48D2-99C1-E928469F7C53}"
Expand Down Expand Up @@ -37,6 +37,22 @@ Global
{173ADCB0-C964-48D2-99C1-E928469F7C53}.Release|iPhone.Build.0 = Release|Any CPU
{173ADCB0-C964-48D2-99C1-E928469F7C53}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{173ADCB0-C964-48D2-99C1-E928469F7C53}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Ad-Hoc|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.Build.0 = Ad-Hoc|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.ActiveCfg = AppStore|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.Build.0 = AppStore|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.ActiveCfg = Debug|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.Build.0 = Debug|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.ActiveCfg = Release|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.Build.0 = Release|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
{8ECDFDC5-42D0-4540-9691-830EEB2ED874}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
{8ECDFDC5-42D0-4540-9691-830EEB2ED874}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{8ECDFDC5-42D0-4540-9691-830EEB2ED874}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -67,27 +83,8 @@ Global
{E6E84D09-BE15-460D-A317-45248BE1C56F}.Release|iPhone.Build.0 = Release|iPhone
{E6E84D09-BE15-460D-A317-45248BE1C56F}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{E6E84D09-BE15-460D-A317-45248BE1C56F}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Ad-Hoc|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.Build.0 = Ad-Hoc|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.ActiveCfg = AppStore|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.Build.0 = AppStore|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.ActiveCfg = Debug|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.Build.0 = Debug|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.ActiveCfg = Release|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.Build.0 = Release|iPhone
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = BTProgressHUDDemo\BTProgressHUDDemo.csproj
EndGlobalSection
EndGlobal
2 changes: 0 additions & 2 deletions BTProgressHUD/BTProgressHUD-Classic.csproj
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{173ADCB0-C964-48D2-99C1-E928469F7C53}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
Expand Down
2 changes: 0 additions & 2 deletions BTProgressHUD/BTProgressHUD.csproj
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8ECDFDC5-42D0-4540-9691-830EEB2ED874}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
Expand Down
36 changes: 20 additions & 16 deletions BTProgressHUD/ProgressHUD.cs
Expand Up @@ -26,6 +26,7 @@




#else
using MonoTouch.UIKit;
using MonoTouch.Foundation;
Expand Down Expand Up @@ -190,6 +191,8 @@ public static ProgressHUD Shared
{
get
{


if (sharedHUD == null)
sharedHUD = new ProgressHUD(UIScreen.MainScreen.Bounds);
return sharedHUD;
Expand Down Expand Up @@ -418,7 +421,7 @@ void ShowImageWorker(UIImage image, string status, TimeSpan duration)
void StartDismissTimer(TimeSpan duration)
{
#if __UNIFIED__
_fadeoutTimer = NSTimer.CreateTimer(duration, timer => DismissWorker ());
_fadeoutTimer = NSTimer.CreateTimer(duration, timer => DismissWorker());
#else
_fadeoutTimer = NSTimer.CreateTimer(duration, DismissWorker);
#endif
Expand All @@ -431,7 +434,7 @@ void StartProgressTimer(TimeSpan duration)
if (_progressTimer == null)
{
#if __UNIFIED__
_progressTimer = NSTimer.CreateRepeatingTimer (duration, timer => UpdateProgress ());
_progressTimer = NSTimer.CreateRepeatingTimer(duration, timer => UpdateProgress());
#else
_progressTimer = NSTimer.CreateRepeatingTimer(duration, UpdateProgress);
#endif
Expand Down Expand Up @@ -991,36 +994,35 @@ void UpdatePosition(bool textOnly = false)
nfloat stringHeightBuffer = 20f;
nfloat stringAndImageHeightBuffer = 80f;

/*if (IsiOS7)
{
hudHeight += 50;
hudWidth += 50f;
stringHeightBuffer += 50f;
stringAndImageHeightBuffer += 50f;
}*/


CGRect labelRect = new CGRect();

string @string = StringLabel.Text;

// False if it's text-only
bool imageUsed = (ImageView.Image != null) || (ImageView.Hidden);
if (textOnly)
{
imageUsed = false;
}

if (imageUsed)
{
hudHeight = stringAndImageHeightBuffer + stringHeight;
}
else
{
hudHeight = (textOnly ? stringHeightBuffer : stringHeightBuffer + 40);
}

if (!string.IsNullOrEmpty(@string))
{
int lineCount = Math.Min(10, @string.Split('\n').Length + 1);

if (IsIOS7OrNewer)
{
var stringSize = new NSString(@string).GetSizeUsingAttributes(new UIStringAttributes{ Font = StringLabel.Font });
var stringSize = new NSString(@string).GetBoundingRect(new CGSize(200, 30 * lineCount), NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes{ Font = StringLabel.Font },
null);
stringWidth = stringSize.Width;
stringHeight = stringSize.Height;
}
Expand All @@ -1047,7 +1049,7 @@ void UpdatePosition(bool textOnly = false)
hudWidth += 24;
}
else
{
{
hudWidth += 24;
labelRect = new CGRect(0, labelRectY, hudWidth, stringHeight);
}
Expand All @@ -1062,7 +1064,9 @@ void UpdatePosition(bool textOnly = false)

if (IsIOS7OrNewer)
{
var stringSize = new NSString(@cancelCaption).GetSizeUsingAttributes(new UIStringAttributes{ Font = StringLabel.Font });
var stringSize = new NSString(@cancelCaption).GetBoundingRect(new CGSize(200, 300), NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes{ Font = StringLabel.Font },
null);
stringWidth = stringSize.Width;
stringHeight = stringSize.Height;
}
Expand Down Expand Up @@ -1090,14 +1094,14 @@ void UpdatePosition(bool textOnly = false)
if (hudHeight > 100)
{
cancelRect = new CGRect(12, cancelRectY, hudWidth, stringHeight);
labelRect = new CGRect(12, labelRect.Y, hudWidth, stringHeight);
labelRect = new CGRect(12, labelRect.Y, hudWidth, labelRect.Height);
hudWidth += 24;
}
else
{
hudWidth += 24;
cancelRect = new CGRect(0, cancelRectY, hudWidth, stringHeight);
labelRect = new CGRect(0, labelRect.Y, hudWidth, stringHeight);
labelRect = new CGRect(0, labelRect.Y, hudWidth, labelRect.Height);
}
CancelHudButton.Frame = cancelRect;
hudHeight += (cancelRect.Height + gap);
Expand Down
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E6E84D09-BE15-460D-A317-45248BE1C56F}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
Expand Down
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{620134FD-4E54-4459-8E18-8B6E1C8A2274}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
Expand Down
95 changes: 58 additions & 37 deletions samples/BTProgressHUDSample/BTProgressHUDSample/MainView.cs
Expand Up @@ -16,113 +16,134 @@ namespace BTProgressHUDDemo
{
public class MainViewController : UIViewController
{
public MainViewController ()
public MainViewController()
{

}

UITextView text;
float progress = -1;
NSTimer timer;
public override void LoadView ()

public override void LoadView()
{
base.LoadView ();
base.LoadView();
View.BackgroundColor = UIColor.LightGray;

MakeButton ("Show", () => {
BTProgressHUD.Show ();
KillAfter ();
MakeButton("Show", () =>
{
BTProgressHUD.Show();
KillAfter();
});

MakeButton ("Show Message", () => {
BTProgressHUD.Show ("Processing your image", -1, ProgressHUD.MaskType.Black);
KillAfter ();
MakeButton("Cancel problem", () =>
BTProgressHUD.Show("Cancel", () => KillAfter(), "This is a multilinetext\nSome more text\n more text\n and again more text")
);

MakeButton("Show Message", () =>
{
BTProgressHUD.Show("Processing your image", -1, ProgressHUD.MaskType.Black);
KillAfter();
});

MakeButton ("Show Success", () => {
BTProgressHUD.ShowSuccessWithStatus("Great success!") ;
MakeButton("Show Success", () =>
{
BTProgressHUD.ShowSuccessWithStatus("Great success!");
});

MakeButton ("Show Fail", () => {
BTProgressHUD.ShowErrorWithStatus("Oh, thats bad") ;
MakeButton("Show Fail", () =>
{
BTProgressHUD.ShowErrorWithStatus("Oh, thats bad");
});

MakeButton ("Toast", () => {
BTProgressHUD.ShowToast("Hello from the toast", showToastCentered: false, timeoutMs:1000) ;
MakeButton("Toast", () =>
{
BTProgressHUD.ShowToast("Hello from the toast", showToastCentered: false, timeoutMs: 1000);
});


MakeButton ("Dismiss", () => {
BTProgressHUD.Dismiss ();
MakeButton("Dismiss", () =>
{
BTProgressHUD.Dismiss();
});

MakeButton ("Progress", () => {
MakeButton("Progress", () =>
{
progress = 0;
BTProgressHUD.Show("Hello!", progress);
if (timer != null)
if (timer != null)
{
timer.Invalidate();
}
timer = NSTimer.CreateRepeatingTimer(0.5f, delegate {
timer = NSTimer.CreateRepeatingTimer(0.5f, delegate
{
progress += 0.1f;
if (progress > 1)
{
timer.Invalidate();
timer = null;
BTProgressHUD.Dismiss();
} else {
BTProgressHUD.Show ("Hello!", progress);
}
else
{
BTProgressHUD.Show("Hello!", progress);
}
});
NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
});

MakeButton ("Dismiss", () => {
BTProgressHUD.Dismiss ();
MakeButton("Dismiss", () =>
{
BTProgressHUD.Dismiss();
});

}

void KillAfter (float timeout = 1)
void KillAfter(float timeout = 1)
{
if (timer != null)
if (timer != null)
{
timer.Invalidate();
}
timer = NSTimer.CreateRepeatingTimer(timeout, delegate {
timer = NSTimer.CreateRepeatingTimer(timeout, delegate
{
BTProgressHUD.Dismiss();
});
NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
}

float y = 20;

void MakeButton(string text, Action del)
{
float x = 20;

var button = new UIButton (UIButtonType.RoundedRect);
button.Frame = new RectangleF (x, y, 280, 40);
button.SetTitle (text, UIControlState.Normal);
button.TouchUpInside += (o,e) => {
del() ;
var button = new UIButton(UIButtonType.RoundedRect);
button.Frame = new RectangleF(x, y, 280, 40);
button.SetTitle(text, UIControlState.Normal);
button.TouchUpInside += (o, e) =>
{
del();
};
View.Add (button);
View.Add(button);


y += 45;

}

public override void ViewDidLoad ()
public override void ViewDidLoad()
{
base.ViewDidLoad ();
base.ViewDidLoad();

}

public override void ViewDidAppear (bool animated)
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear (animated);
base.ViewDidAppear(animated);

}
}
Expand Down

0 comments on commit b16535f

Please sign in to comment.