In my app I make a viewcontroller that contain imageview and custom navigation bar and connect navigationbaritem and navigationbar outlets to code .
I define UINavigationBar and UINavigationItem as outlet.
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar;
#property (weak, nonatomic) IBOutlet UINavigationItem *barItem1;
#property (weak, nonatomic) IBOutlet UILabel *label;
#end
When image don't load every thing okay but when I fetch image and load view height of navigation bar changed. How can I prevent to stretch navigation bar?
i use xcode 7.3 and ios 9.X.
i define
image description :
enter image description here
You can prevent your bar from stretching by hardcoding the height value of your bar element in the storyboard.
To do this you need to set the height constraint of your element.
Related
In ViewController i have two property of containers:
#property (weak, nonatomic) IBOutlet UIView *firstContainerView;
#property (weak, nonatomic) IBOutlet UIView *secondContainerView;
And i can do everything with them:
self.firstContainerView.alpha = 0;
self.secondContainerView.alpha = 1;
But how i can appear firstContainerView from SecondVC method (click button) ?
First of all you must have a pointer to access the target view controller so you see two vc not have a connection so you should create a global pointer for another vc to access. You can create a singleton to hold these vc or just use a delegate or block.
Why don't use a delegate to inform ViewController that button is clicked and ViewController will take care of appearing/disappearing the containers views.
I am trying to include a tab bar, with 4-5 tab bar items on it, to multiple view controllers of my app and will work as menu to jump between views (Map, About, Favourites etc.).
I have created on Storyboard a UITabBar item and set its Bar item's tags. Because the same tab bar will be used on several other view controllers (Main, View2, View3 etc.) I've decided to create a class that extends UITabBar. This will help me to customise the bar later. The UITabBar object in Storyboard is now an object of this class (BottomTabBar).
My question is, how I can detect when a bar item has been tapped?
In addition, because I am not familiar with TabBar, if you have any general guides or tips that will help me during development please share them with me.
BottomTabBar.h
#import <UIKit/UIKit.h>
#interface BottomTabBar : UITabBar <UITabBarDelegate>
#end
BottomTabBar.m
#import "BottomTabBar.h"
#implementation BottomTabBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.delegate = self;
}
return self;
}
- (void) tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSLog(#"Tabbed!");
}
#end
MainViewController.h
#import <UIKit/UIKit.h>
#import "BottomTabBar.h"
#interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
AppDelegate *appDelegate;
NSArray *searchResults;
}
#property (strong, nonatomic) IBOutlet UIScrollView *slideshow;
#property (strong, nonatomic) IBOutlet UIPageControl *scroll;
#property (strong, nonatomic) IBOutlet BottomTabBar *bottomBar;
#end
This guide is really good:
http://www.rumex.it/2010/07/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-1-of-2/
Notice there is also a second part there.
See this tutorials and source codes for custom tab bar.
Custom tabbar
I hope it helps you.
I have a subclassed view controller and in Interface Builder I want a subview of the VC's view to be a UIPageViewController's view. I set the UIPageViewController's datasource to File's Owner and the view property to the subview of my VC. Can this functionality be achieved? or I can't use the UIPageVC in that way? Most of the examples are for storyboards and not the old VC pushed by NavigationController way. I get this exception '[UIView invalidatePageViewController]'.
I had the same thing happen to me when I had a UIViewController as my root view - and my UIViewController had an attribute defined as:
#property (strong, nonatomic) IBOutlet UIPageViewController *pageViewController;
My IBoutlet was also connected to a UIPageViewController in my xib.
The solution: Remove the IBoutlet and disconnect the UIPageViewController from my xib
#property (strong, nonatomic) UIPageViewController *pageViewController;
Maybe the crash is related to 'there should only be one view controller per view'
Also, in the 'viewdidload' if you do
_pageViewController.view = _apageView;
where _apageView is in your UIViewController as:
#property (strong, nonatomic) IBOutlet UIView *apageView;
This will also cause the same crash to happen - therefore you would need to do:
[_apageView addSubview:_pageController.view];
Then the crash shouldn't happen.
I'd like to develop for iOS5 and have a storyboard...
I've just created UIView with UIViewController on the storyboard.
I have added a lot of other UIButtons and labels and creates outlets to VC.
I would like to use this view with it's viewcontroller 3 times on a single parent view.
How is it possible? I dont want to copy "a lot of other UIButtons and labels" ...
Maybe i should create this view out of storyboard in separate XIB? How will i use XIB in storyboard?
UPDATE:
Thanx you, Juzzz - your solution works perfect:
You have to create 2 custom viewControllers (one for each view in your story board.
example:
#interface GraphCollectionViewController : UIViewController
#interface GraphViewController : UIViewController
To connect them you can use something called: UIViewController containment
For your GraphCollectionViewController create 3 outlets for your UIViews. Then create 3 properties of GraphViewController's (or an array, what you want) and initialize them in the view did load.
#property (strong, nonatomic) IBOutlet UIView *topView;
#property (strong, nonatomic) IBOutlet UIView *middleView;
#property (strong, nonatomic) IBOutlet UIView *bottomView;
#property (strong, nonatomic) GraphViewController *topGraphViewController;
#property (strong, nonatomic) GraphViewController *middleGraphViewController;
#property (strong, nonatomic) GraphViewController *bottomGraphViewController;
...
//top graph
self.topGraphViewController = [storyboard instantiateViewControllerWithIdentifier:#"GraphViewController"]; //init with view from storyboard
self.topGraphViewController.view.frame = self.topView.bounds; //set frame the same
[self.view addSubview:self.topGraphViewController.view];
[self addChildViewController:self.topGraphViewController];
[self.topGraphViewController didMoveToParentViewController:self];
//middle graph
self.middleGraphViewController = [storyboard instantiateViewControllerWithIdentifier:#"GraphViewController"]; //init with view from storyboard
self.middleGraphViewController.view.frame = self.middleView.bounds; //set frame the same
[self.view addSubview:self.middleGraphViewController.view];
[self addChildViewController:self.middleGraphViewController];
[self.middleGraphViewController didMoveToParentViewController:self];
//bottom graph
self.bottomGraphViewController = [storyboard instantiateViewControllerWithIdentifier:#"GraphViewController"]; //init with view from storyboard
self.bottomGraphViewController.view.frame = self.bottomView.bounds; //set frame the same
[self.view addSubview:self.bottomGraphViewController.view];
[self addChildViewController:self.bottomGraphViewController];
[self.bottomGraphViewController didMoveToParentViewController:self];
I think you get the point. For more understanding this example .
You can create a new view class (with it's own .h, .m files) and base this on the ViewController you created yourself.
So as for code:
#interface ViewController : UIViewController
Let's say the above is your original ViewController that you want to use in other places.
This has buttons, labels, etc. in it.
When you create a new view class base it on your own instead of UIViewController class like this:
#interface MyNewController : ViewController
Now that MyNewController is based on ViewController you created earlier, it should have it's buttons, labels, etc. you created as well.
Edit: You might also have to change your view's base class in the storyboard.
Click on the view you want to change, look at the right hand side attributes window, under Custom Class choose your own controller, in this case ViewController.
I'm creating some outlets for my UI scroll views.
These outlets show up just fine in the iPhone Interface Builder but in the iPad interface builder they are nowhere to be seen.
Any idea why?
#interface ViewController : UIViewController {
IBOutlet UIScrollView *scroller;
IBOutlet UIScrollView *scrollerLong;
IBOutlet UIScrollView *scrollerHuge;
IBOutlet UIScrollView *scrollerMassive;
IBOutlet UIScrollView *mediumScroll;
IBOutlet UIScrollView *scrollerHome;
}
You can set a property in the header file:
#property(retain, nonatomic) IBOutlet UIScrollView *scroller;