I am trying to put kGADAdSizeSmartBannerLandscape at the bottom of my screen.
Here is my code. Please help.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape] ;
bannerView_.adUnitID = #"AD ID";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
Simple.. Create a blank View at the bottom with size of 0, 678, 1024, 90 for ipad and similarly for ipod. And then add bannerView_ as a subview of that newly created View
Related
I am using the following code to create my scrollview. I would like to move the scrollView down 44px to make room for my nav bar.
scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scroll.backgroundColor = [UIColor clearColor];
scroll.delegate = self;
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Menu.png"]];
scroll.contentSize = image.frame.size;
[scroll addSubview:image];
scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
scroll.maximumZoomScale = 2.0;
[scroll setZoomScale:scroll.minimumZoomScale];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[scroll addGestureRecognizer:doubleTap];
self.view = scroll;
any help is appreciated.
Your code is correct, to manually create a frame do:
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,44,320,480)];
:)
This is for iPod and iphone View but this will let the scroll start at 44px
Cant you just add a scroll view in in interface builder as an outlet, place it underneath your nav bar.
Declare scroll view in .h
in .m under ViewDidLoad
[scroll setScrollEnabled:YES];
[scroll setContentSize: CGSizeMake(320, 1000)]; ////or whatever size you want here
You probably want to init it with a different frame... but it depends on where/how this nav bar is being created. If you have a view controller, and these are all subviews of the view controller's view, then you should be creating the objects in viewDidLoad, then just create the nav bar first, using self.view.bounds to obtain the initialization width. I assume you'll want to put UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin as the autoResizingMask here. Then if the scrollview is the rest of the view below the nav bar, you can create the frame for it using
CGRect scrollFrame = CGRectInset(self.view.bounds, 0, navbar.bounds.size.height)
Put an autoresizingMask of UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHeight on the scrollview.
If you are creating the views in a different place/way, then some of that might need modification. I was assuming your view is a nav bar at the top, x pixels tall (44 in this case but it doesn't and shouldn't matter in the context of setting the scrollview frame). and then a scrollview that fills the rest of the view.
I am creating one app in which i have to use navigation image.
without navigation image i can see the toolbar option perfectly
navigation bar without image at app start up-home screen
navigation image after navigate to second page
now i am adding an image in my navigation bar using
UIImageView *topBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 45)];
topBar.image = [UIImage imageNamed:#"top_cell.png"];
[self.navigationController.navigationBar addSubview:topBar];
now the navigation bar look like at home screen perfect
but in second page the toolbar option hidden
so how can i show toolbar above the image in navigation bar?
Try with
[self.navigationController.navigationBar insertSubview:topBar belowSubview:navigationBar];
It will insert your view under your navigation bar.
A second option is to use this code after yours:
[self.navigationController.navigationBar bringSubviewToFront: topBar]
that will put your top bar at the top of the view stack.
finally lots of work i found the solution first i have added image in viewWillAppear method then after i added my toolbar in viewDidAppear method just like below code
-(void)viewWillAppear:(BOOL)animated
{
// self.navigationController.navigationBarHidden = TRUE;
///// Edit Hiren
UIImageView *topBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 45)];
topBar.image = [UIImage imageNamed:#"top-bar.png"];
[self.navigationController.navigationBar addSubview:topBar];
}
-(void)viewDidAppear:(BOOL)animated
{
toolbar.frame = CGRectMake(0, 0, 685, 44);
// [toolbar sizeToFit];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
// [self.navigationController.view addSubview:toolbar];
}
I have the following code that allows me to position it on the top. I am wanting it to appear at the bottom.
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
Any assistance will be appreciated.
Update—#larsacus pointed out this is for 4.2+:
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
CGRect adFrame = adView.frame;
adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
adView.frame = adFrame;
[self.view addSubview:adView];
My first answer on SO :)
Why not use the 'center' property of the adView? If the dimensions of your main view are viewWidth and viewHeight:
//at the bottom of view,centered
adView.center=CGPointMake(viewWidth/2, viewHeight-adView.frame.size.height);
//at the top, right corner ;)
adView.center=CGPointMake(viewWidth-adView.frame.size.width/2, adView.frame.size.height);
Cheers
This is what helped me move the view to the bottom:
adFrame.origin.y = self.view.frame.size.height;
adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
Using Storyboards, then, ignore that the standard iAd Banner View does not reach the edges of the screen.
Set the iAd banner to be centred, then move it to as close to the bottom as you want. No other width settings (no leading or trailing settings)
Mine looked ok with 8 pixels from the bottom of the superview, but I went with - pixels between the iAd banner and the UIController View.
I have added a UISearchBar to a table in my iPad app using the below code. The table is on the left hand side of my split view controller.
The problem is that when the app starts the search bar is strangely off screen to the left - you can just see the last few pixels of it. If you click on it, or scroll down and back up, it reverts itself and looks like it should.
Can anyone suggest how to fix this ?
Thanks
searchBar = [[UISearchBar alloc] init];
self.tableView.tableHeaderView = searchBar;
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar
contentsController:self];
searchBar.delegate = self;
searchController.delegate = self;
searchController.searchResultsDelegate=self;
searchController.searchResultsDataSource=self;
You can try to create the UISearchBar with a frame like:
CGRect searchViewFrame = CGRectMake(33, 33, 264, 31);
or whatever dimensions or origin.
Like other resource, you can create the UISearchBar within a UIView, and add this UIView to the UITableView:
UIView *containerSearch = [[UIView alloc] initWithFrame: searchViewFrame];
searchBar = [[UISearchBar alloc] init];
[containerSearch addSubview: searchBar];
self.tableView.tableHeaderView = containerSearch;
So, my iPad program has a pseudo-split view controller (one that I implemented, not base SDK one), and was working correctly a while ago. It has the basic layout (UINavController for master, content view controller for detail on right), but I have it so the master view doesn't disappear when rotated into portrait view.
Recently, I added in a UITabBarController to contain the entire split view, which has made the navigation bar go wonky, while all the other views are positioned fine. In addition, the navigation bar only gets mispositioned when the program starts up while the iPad is in landscape, or upside-down portrait. If it starts out in portrait, everything is fine.
Example images can be found here:
http://profile.imageshack.us/user/Pzychotix
Image where the navigation bar is upwards is when I initially launch the program.
Image where the navigation bar is downwards is after I rotate once or more times.
Relevant Code:
RootViewController.m:
- (void)loadView {
navController = [[NavigationBreadcrumbsController_Pad alloc] init];
ABTableViewController_Pad * tableViewController = [[ABTableViewController_Pad alloc] initWithNibName:#"ABTableView"];
master = [[UINavigationController_Pad alloc] initWithRootViewController:tableViewController];
[tableViewController release];
// Dummy blank UIViewcontroller
detail = [[UIViewController alloc] init];
detail.view = [[[UIView alloc] init] autorelease];
[detail.view setBackgroundColor:[UIColor grayColor]];
self.view = [[[UIView alloc] init] autorelease];
self.view.backgroundColor = [UIColor blackColor];
[self positionViews];
[self.view addSubview:navToolbarController.view];
[self.view addSubview:master.view];
[self.view addSubview:detail.view];
}
// Handles the respositioning of view into it's current orientation
-(void)positionViews{
CGFloat tabBarOffset = 0;
if(self.tabBarController){
tabBarOffset = self.tabBarController.tabBar.frame.size.height;
}
if(self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
self.view.frame = CGRectMake(0, 0, 768, 1004);
navController.view.frame = CGRectMake(0,0,768,44);
//adjust master view
[master.view setFrame:CGRectMake(0, 44, 320, 1024 - 44 - 20 - tabBarOffset)];
//adjust detail view
[detail.view setFrame:CGRectMake(321,44, 448, 1024 - 44 - 20 - tabBarOffset)];
}
// Landscape Layout
else{
self.view.frame = CGRectMake(0, 0, 748, 1024);
navToolbarController.view.frame = CGRectMake(0,0,1024,44);
//adjust master view
[master.view setFrame:CGRectMake(0, 44, 320, 768 - 44 - 20 - tabBarOffset)];
//adjust detail view
[detail.view setFrame:CGRectMake(321,44, 1024 - 320, 768 - 44 - 20 - tabBarOffset)];
}
}
Well I've found a solution, though I'm still scratching my head as to why it's working.
Basically, I called layoutIfNeeded on my UINavigationController, and that fixed everything right up. What I don't understand is why it was working before, or why I would need to call layoutIfNeeded, as I assumed setFrame would automatically deal with laying out any subviews of controllers.