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

Commit

Permalink
closes #1 - better header padding calculation on ServerVC
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Mar 6, 2013
1 parent dec13b6 commit aed0ddd
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions buyvmmanager/BVMServerViewController.m
Expand Up @@ -68,15 +68,12 @@ @interface BVMServerViewController () <BVMPingerDelegate>

@property (nonatomic, strong, readonly) MBProgressHUD *progressHUD;

@property (nonatomic, assign, readonly) CGFloat headerViewSidePadding;

@end

@implementation BVMServerViewController

@synthesize reloadButtonItem = _reloadButtonItem,
progressHUD = _progressHUD,
headerViewSidePadding = _headerViewSidePadding
progressHUD = _progressHUD
;

- (id)initWithServerId:(NSString *)serverId name:(NSString *)serverName
Expand All @@ -103,6 +100,17 @@ - (void)viewDidLoad
[self reloadData];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self adjustTableViewHeaderPaddingForOrientation:[[UIDevice currentDevice] orientation]];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self adjustTableViewHeaderPaddingForOrientation:toInterfaceOrientation];
}

#pragma mark BVM Data Management

- (void)reloadData
Expand Down Expand Up @@ -524,6 +532,32 @@ -(BOOL)tableView:(UITableView*)tableView shouldShowMenuForRowAtIndexPath:(NSInde
return NO;
}

#pragma mark UI Adjustments

- (void)adjustTableViewHeaderPaddingForOrientation:(UIDeviceOrientation)orientation
{
CGFloat padding;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
padding = 10;
} else { // pad
if (UIDeviceOrientationIsPortrait(orientation)) {
padding = 30;
} else { // landscape
padding = 45;
}
}

CGRect hostnameFrame = self.headerHostnameLabel.frame;
hostnameFrame.origin.x = padding;
hostnameFrame.size.width = self.tableView.bounds.size.width - 2*padding;
self.headerHostnameLabel.frame = hostnameFrame;

CGRect headerStatusLabelFrame = self.headerStatusLabel.frame;
headerStatusLabelFrame.origin.x = padding;
headerStatusLabelFrame.size.width = self.tableView.bounds.size.width - 2*padding;
self.headerStatusLabel.frame = headerStatusLabelFrame;
}

#pragma mark Property overrides

- (UIView *)headerView {
Expand All @@ -533,15 +567,15 @@ - (UIView *)headerView {
_headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_headerView.backgroundColor = [UIColor clearColor];

self.headerHostnameLabel = [[UILabel alloc] initWithFrame:(CGRect){ {self.headerViewSidePadding, 10} , { _headerView.bounds.size.width-2*self.headerViewSidePadding, 35 }}];
self.headerHostnameLabel = [[UILabel alloc] initWithFrame:(CGRect){ {0, 10} , { _headerView.bounds.size.width, 35 }}];
self.headerHostnameLabel.font = [UIFont boldSystemFontOfSize:22.0];
self.headerHostnameLabel.backgroundColor = [UIColor clearColor];
self.headerHostnameLabel.text = NSLocalizedString(@"Loading...", nil);
self.headerHostnameLabel.shadowColor = [UIColor bvm_darkGrayTextShadowColor];
self.headerHostnameLabel.shadowOffset = CGSizeMake(0, 1.0);
[_headerView addSubview:self.headerHostnameLabel];

self.headerStatusLabel = [[UILabel alloc] initWithFrame:(CGRect){ {self.headerViewSidePadding, 41} , { self.headerHostnameLabel.bounds.size.width, 20 }}];
self.headerStatusLabel = [[UILabel alloc] initWithFrame:(CGRect){ {0, 41} , { _headerView.bounds.size.width, 20 }}];
self.headerStatusLabel.font = [UIFont boldSystemFontOfSize:18.0];
self.headerStatusLabel.backgroundColor = [UIColor clearColor];
self.headerStatusLabel.shadowColor = self.headerHostnameLabel.shadowColor;
Expand Down Expand Up @@ -577,16 +611,4 @@ - (MBProgressHUD *)progressHUD
return _progressHUD;
}

- (CGFloat)headerViewSidePadding
{
if (!_headerViewSidePadding) {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
_headerViewSidePadding = 36;
} else {
_headerViewSidePadding = 18;
}
}
return _headerViewSidePadding;
}

@end

0 comments on commit aed0ddd

Please sign in to comment.