iPad - UISplitViewController - Background color - ipad

I have a UISplitViewController setup, but for some reason the background isn't taking hold until you've rotated it once.
I use IB to setup the split view and set the detail view to be IPadDetailViewController. Inside that I have the following:
- (void)loadView {
[super loadView];
self.view.backgroundColor = [UIColor greenColor];
toolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
toolbar.barStyle = UIBarStyleDefault;
[toolbar sizeToFit];
[self.view addSubview:toolbar];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.view.backgroundColor = [UIColor orangeColor];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"it is in landscape!");
self.view.backgroundColor = [UIColor grayColor]];
}
else {
NSLog(#"it is in portrait!");
self.view.backgroundColor = [UIColor blueColor];
}
}
Though the code gets run and my toolbar gets place at the top, the view remains black (it starts in landscape for the Simulator).
Any ideas why?

try setting the background color in awakeFromNib method in your iPadDetailViewController

Related

UINavigationBar - Hide Subview in nested pages

I have added a message count using the MKNumberBadgeView via the following code in my uiTableView Homepage -
-(void)counterBtn{
_numberBadge = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(25, -10, 40, 40)];
_numberBadge.strokeColor = [UIColor colorWithRed:239.0/255.0 green:117.0/255.0 blue:33/255.0 alpha:0];
_numberBadge.fillColor = [UIColor colorWithRed:239.0/255.0 green:117.0/255.0 blue:33/255.0 alpha:1];
_numberBadge.shine = NO;
_numberBadge.hideWhenZero = YES;
_numberBadge.value = _countBtnNo;
[self.navigationController.navigationBar addSubview:_numberBadge];
}
All works fine - but if I navigate from this view to a subview the counter is still shown over the back button as in screenshot -
Is it possible to temporarily hide this button - then show it again when I return to the homepage?
I was thinking something along these lines in the subview's viewdidload method? -
[self.navigationController.navigationBar.subviews setHidden:YES];
Try this in HomeScreen:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
_numberBadge.hidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_numberBadge.hidden = YES;
}

Navigation controller with 2 navigation bars - how to adjust frame of pushed view controllers?

I have a UINavigationController to which I need to add a second UINavigationBar. Neither of those bars is translucent. Problem is, view controllers that I put inside this navigation controller are partially covered by my second navigation bar. Where do I adjust the frames of those view controllers' views so that I don't get a "blinking" effect of them changing frames while being visible?
EDIT:
This is in viewDidLoad:
UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
secondaryNavBar.translucent = NO;
if ([secondaryNavBar respondsToSelector:#selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
secondaryNavBar.barTintColor = [UIColor darkGrayColor];
secondaryNavBar.tintColor = [UIColor whiteColor];
}
else {
secondaryNavBar.tintColor = [UIColor darkGrayColor];
}
[self.view addSubview:secondaryNavBar];
self.secondaryNavBar = secondaryNavBar;
Here's a working solution. Certainly not the best, and I did not make it to support iOS 6, you'll have to work on it and test it.
CustomNavigationController.m :
#implementation CustomNavigationController {
UINavigationBar *bottomNavBar;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self showNavBar];
}
- (void)showNavBar {
UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
secondaryNavBar.translucent = NO;
if ([secondaryNavBar respondsToSelector:#selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
secondaryNavBar.barTintColor = [UIColor darkGrayColor];
secondaryNavBar.tintColor = [UIColor whiteColor];
}
else {
secondaryNavBar.tintColor = [UIColor darkGrayColor];
}
[self.view addSubview:secondaryNavBar];
bottomNavBar = secondaryNavBar;
[self layoutNavBar];
}
- (void)layoutNavBar {
// Get the currently displayed view
UIView *contentView = self.topViewController.view;
// Get its frame and height
CGRect contentFrame = contentView.frame;
float height = contentFrame.size.height;
// Adapt height and y origin with the new nav bar
contentFrame.size.height = height - bottomNavBar.frame.size.height;
contentFrame.origin.y = bottomNavBar.frame.origin.y + bottomNavBar.frame.size.height;
// Set the view's frame
contentView.frame = contentFrame;
}
#end
ViewController.m :
#implementation ViewController
-(void)viewDidAppear:(BOOL)animated {
CustomNavigationController *navigation = (CustomNavigationController*)self.navigationController;
[navigation layoutNavBar];
}
#end
Note that you have to call layoutNavBar on viewDidAppear, or the view's frame will be reset by your app. This is not a perfectly clean solution, but a pretty good fix.

iOS 7 UITableView inside a popover

I have a UITableView which has some custom styling. This table view appears in two places in the app, one of which is inside a UIPopoverController. However when the tableview is inside the popover it takes on the default tableview styling as stated in the UI Transition Guide under "Popover".
The problem I have is that there appears to be nowhere to change this behaviour. Regardless of where I try and modify properties of the tableview the view inside the popover doesn't change.
Anyone dealt with this issue before or have any ideas?
Here is the init method of LibraryProductView where I create the table view:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.sectionOrdering = [NSArray arrayWithObjects:
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DESCRIPTION],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DOCUMENTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_ACTIVE_INGREDIENTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_PRODUCTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_DOCUMENTS], nil];
self.backgroundColor = [UIColor whiteColor];
self.tableView = [[UITableView alloc] initWithFrame:CGRectInset(self.bounds, 10, 0) style:UITableViewStyleGrouped];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.showsVerticalScrollIndicator = NO;
[self addSubview:self.tableView];
}
return self;
}
Here is where the containing view (LibraryProductView) is added to the popover:
- (IBAction)didTouchInformationButton:(id)sender
{
if (_infoPopover != nil && _infoPopover.isPopoverVisible)
{
[_infoPopover dismissPopoverAnimated:YES];
return;
}
CGSize preferredSize = CGSizeMake(600.0f, 500.0f);
LibraryProductViewController* productController = [[[LibraryProductViewController alloc] initWithPreferredSize:preferredSize] autorelease];
productController.filterByMyCompany = NO;
productController.product = _activityInput.product;
UINavigationController* nav = [[[UINavigationController alloc] initWithRootViewController:productController] autorelease];
nav.title = _activityInput.product.name;
RELEASE(_infoPopover);
_infoPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
_infoPopover.popoverContentSize = CGSizeMake(preferredSize.width, preferredSize.height + 46);
[_infoPopover presentPopoverFromRect:_infoButton.frame inView:_infoButton permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
The LibraryProductView is created within viewDidLoad method of LibraryProductViewController.
- (void)viewDidLoad
{
[super viewDidLoad];
self.libraryProductView = [[LibraryProductView alloc] initWithFrame:(usingPreferredSize ? CGRectMake(0.0, 0.0, preferredSize.width, preferredSize.height) : self.view.bounds)];
self.libraryProductView.dataSource = self;
self.libraryProductView.delegate = self;
[self.view addSubview:self.libraryProductView];
}
To set properties for the TableView you might do so in
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
[tableView setBackgroundColor:[UIColor redcolor]];
[tableView setSeparatorColor: [UIColor blueColor]];
return 1;
}
This, of course, assumes you have set UITableViewDataSource in your .h file

The background colour of a grouped UITableView will not go transparent in iOS7

I am working on an app, which worked perfectly fine with iOS 6. With iOS7 the app has couple of layout and general few appearance issues. One is not being able to set the background color of a grouped tableview to transparent. Heres is my code which does not work anymore
tableForDetails = [[UITableView alloc]initWithFrame:CGRectMake(0, yAxisTable, 320, 150) style:UITableViewStyleGrouped];
UIColor *backGroundColor = [UIColor clearColor];
UIView *bview = [[UIView alloc]init];
[bview setBackgroundColor:backGroundColor];
[tableForDetails setBackgroundView:bview];
Help is greatly appreciated. Thanks
To set background transparency for a grouped uiTableview in iOS7 is really quite easy. The solution is even more simple than I originally thought.
[tableForDetails setBackgroundColor:[UIColor clearColor]];
or for only semi transparent
[tableForDetails setBackgroundColor:[[UIColor alloc]initWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]];
This worked fine for me.
I fixed it with this:
tableView.backgroundView = UIView.new;
I put any kind of improvements on Apple components in a super class. The following upgrades are applied in BasicTableView.m, which extends UITableView:
1) overrides setBackgroundColor to work with iOS 7 and above, while maintaining backward compatibility with iOS 6 and 5.
2) overrides initWithCoder: and initWithFrame:style: to initialize the background color to a default transparent background
- (id) initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self) {
[self setup];
}
return self;
}
- (id) initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
self = [super initWithFrame:frame style:style];
if (self) {
[self setup];
}
return self;
}
- (void) setup
{
//Set the BG color to clear color by default
[self setBackgroundColor:[UIColor clearColor]];
}
- (void) setBackgroundColor:(UIColor *)backgroundColor
{
if (self.style == UITableViewStyleGrouped) {
if (majorSystemVersion() < 7) {
UIView *tableBgView = [[UIView alloc] init];
tableBgView.backgroundColor = backgroundColor;
self.backgroundView = tableBgView;
} else {
[super setBackgroundColor:backgroundColor];
}
}
}
//majorSystemVersion() is defined elsewhere in a utility file
int majorSystemVersion(void) {
NSString *systemVersion = [UIDevice currentDevice].systemVersion;
NSArray *systemVersionComps = [systemVersion componentsSeparatedByString:#"."];
NSString *majorVersion = [systemVersionComps objectAtIndex:0];
return [majorVersion intValue];
}
UITableViewCell is in white Background by default in iOS 7
put this inside your cellforRowAtIndexPath
[cell setBackgroundColor:[UIColor clearColor]]

custom navigationitem titleview wrong frame

hi i just make a custom navigationitem title view, but it looks a bit wrong.
here is the custom view ,it base on a uiview
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_titleLabel=[[[UILabel alloc] init] autorelease];
[self addSubview:_titleLabel];
_actionButton=[UIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:_actionButton];
[_actionButton setImage:[UIImage imageNamed:#"arrow_cal_right"] forState:UIControlStateNormal];
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
[_titleLabel sizeToFit];
[_actionButton sizeToFit];
CGFloat height=44;//MAX(_titleLabel.frame.size.height, _actionButton.frame.size.height);
self.frame=CGRectMake(self.frame.origin.x,
0,
_titleLabel.frame.size.width+_actionButton.frame.size.width+kMargin,
height);
_titleLabel.frame=CGRectMake(0,
(height-_titleLabel.frame.size.height)/2,
_titleLabel.frame.size.width,
_titleLabel.frame.size.height);
_actionButton.frame=CGRectMake(_titleLabel.frame.size.width+kMargin,
(height-_actionButton.frame.size.height)/2,
_actionButton.frame.size.width,
_actionButton.frame.size.height);
}
but when app run, it likes that, the title isn't in the centre
screen shot is here:
http://i.stack.imgur.com/yQVLr.png
set titleLabel backgroundColor as [UIColor clearColor];

Resources