Custom navigation bar height and view - ios4

I want to have a naviagtion bar that is at least the double height.
In didFinishLaunchingWithOptions in my appdelegate.m file, I've added
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 100.f);
[self.navigationController.navigationBar setFrame:frame];
But when I run the app the top part of the table view is behind the bottom of the navigation bar.
How do I resize the table view so it`s not behind the navigation bar?
Thank's
// Sven

If you want to resize your navigation bar in all application viewConttrollers, you can override sizeThatFits:(CGRect) rect method in UINavigationBar category
#implementation UINavigationBar (bigSize)
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(320,100);
return newSize;
}
#end

Related

Creating a horizontal separator in a vertical UIStackView

I have a vertical stack view that contains a number of horizontal stack views. How can I create a 1px separator line between the horizontal stackviews?
You can create a Separator View:
class SeparatorView: UIView {
init() {
super.init(frame: .zero)
setUp()
}
override init(frame: CGRect) {
super.init(frame: frame)
setUp()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setUp() {
backgroundColor = .gray
}
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height:0.5)
}
}
And add it to your StackView in between the horizontal views:
stackView.addArrangedSubview(horizontalView)
stackView.addArrangedSubview(SeparatorView())
This will create a small gray line that separates the views.
just add in a UIView with a 1-2px width and the same height as each of the horizontal stack views in between the two middle most controls in the horizontal stack view. Assuming that there is no top or bottom spacing it would give the impression of a vertical line without breaks, or if you don't mind breaks in the vertical line then don't worry about removing top or bottom spacing.
OR
You could leverage the fact that UIStackView can take subviews, and just work out the centre x, and with a y of 0, add in a 2px wide UIView as a subview of the UIStackView.
Something like:
UIStackView sv = new UIStackView();
UIView ViewLine = new UIView();
ViewLine.Frame = new CGRect(CentreX, 0 , 2f , heightofstackview );
sv.AddSubview();

iOS 9 UINavigation bar content is not centred after rotation in iOS 9?

I noticed a bug in iOS 9, or may be I am not using something correctly.
In the following code in an empty project targeted for iPhone :
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Show" style:UIBarButtonItemStylePlain target:self action:#selector(test:)];
self.navigationItem.rightBarButtonItem = anotherButton;
self.navBar.items = #[self.navigationItem];
I added a custom button to a navigation bar property. I noticed that after rotation from portrait to landscape, the button moves down and it is not centered correctly in the navigation bar.
Portrait Screen
Landscape Screen
This code works fine if I compile for iOS 8.4 for example, but not on iOS 9.
Has anyone encountered this?
Thanks!
I've seen something similar on the iPad. When I start the app in portrait, then rotate to landscape, the View Controller its navigationItem.titleView doesn't align correctly anymore. I simply reset it after rotation as follows in Swift:
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animateAlongsideTransition(nil) { (coordinator) -> Void in
self.navigationItem.titleView = someView
}
}
Swift 3:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: nil) { (coordinator) -> Void in
self.navigationItem.titleView = self.someView
}
}
I have managed to fix the problem with custom navigation bar class with and overridden method:
-(void) layoutSubviews
{
[super layoutSubviews];
for (UIView *view in self.subviews)
{
if ([view isKindOfClass:[UIView class]] ||
[view isKindOfClass:[UIButton class]] ||
[view isKindOfClass:[UISearchBar class]] ||
[view isKindOfClass:[UILabel class]])
{
CGRect frame = view.frame;
frame.origin.y = (self.frame.size.height - frame.size.height) / 2.f;
view.frame = frame;
}
}
}
Other type of view classes can be added in the if statement. Its not the cleanest solution, but it will do for now.

How can I change a color of image and label on UITabBar on iOS 7.1?

How can I change a color of image and label on UITabBar on iOS 7.1? On iOS 7 I could make it by Tint property. But on iOS 7.1 it doesn't work.
It works in the same way in iOS 7 and iOS 7.1!
In AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add this if you only want to change Selected Image color
// and/or selected image text
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// Add this code to change StateNormal text Color,
[UITabBarItem.appearance setTitleTextAttributes:
#{NSForegroundColorAttributeName : [UIColor greenColor]}
forState:UIControlStateNormal];
// then if StateSelected should be different, you should add this code
[UITabBarItem.appearance setTitleTextAttributes:
#{NSForegroundColorAttributeName : [UIColor purpleColor]}
forState:UIControlStateSelected];
return YES;
}
In every ViewController: (if you want to change the unselected image color)
- (void)viewDidLoad
{
[super viewDidLoad];
// changing the unselected image color, you should change the selected image
// color if you want them to be different
self.tabBarItem.selectedImage = [[UIImage imageNamed:#"yourImage_selectedImage"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem.image = [[UIImage imageNamed:#"yourImage_image"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
The clue of this code is 'UIImageRenderingModeAlwaysOriginal':
Rendering Modes by Apple Documentation:
UIImageRenderingModeAutomatic, // Use the default rendering mode for the context where the image is used
UIImageRenderingModeAlwaysOriginal, // Always draw the original image, without treating it as a template
UIImageRenderingModeAlwaysTemplate, // Always draw the image as a template image, ignoring its color information
UITabBarItem has never had a tint property. No built-in class has ever had a tint property. Nothing has changed here.
In iOS 7 and 7.1, a UITabBar has a tintColor property because it is a UIView.
This changes the tint of both the image and the label, when selected.
- (void)viewDidLoad
{
[super viewDidLoad];
[[UITabBar appearance] setTintColor:[UIColor redColor]];
}

UIScrollView won't scroll on iOS 7 after popping the view controller

My app's home screen has a UIScrollView that contains a UIWebView and a UIButton. The scroll view's content size is set accordingly after loading the web view.
The user can return to the home screen at anytime by simply pressing an icon in a tab bar. This action clears all of the view controllers out of the navigation controller and adds the home screen's controller to the navigation controller. The home screen is redisplayed correctly and the scroll view works just fine.
The problem I'm encountering is when the user presses a "back" button to return the to home screen, which pops the current view controller. The page redisplays fine, but you can't scroll anymore.
I've stepped through the code numerous times and the scroll view's content size is being set to the same value no matter which way you return to the home screen.
It's important to note that the scrollview only stops working under iOS 7. It works as expected under iOS 6.
The web page is loaded in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
NSString *fullURL = #"http://somewhere.com/app-homepage/index.html";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
[self.scrollView setContentOffset:CGPointZero];
}
The scroll view is dynamically resized in webViewDidFinishLoad:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
webView.scrollView.scrollEnabled = NO;
CGRect frame = webView.frame;
frame.size.height = 1;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
self.webViewHeightConstraint.constant = frame.size.height;
self.featuredCelebritiesButtonTopVerticalSpaceConstraint.constant = frame.size.height + 8;
CGSize svContentSize = self.scrollView.contentSize;
svContentSize.height = frame.size.height + 65;
self.scrollView.contentSize = svContentSize;
webView.frame = frame;
[self.activity stopAnimating];
}

Change Navigation Bar Tint Color while presenting new view controller modally in iOS 4.x

In my view controller's I have following code
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(#"%s",__PRETTY_FUNCTION__);
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:201.0/255.0 green:201.0/255.0 blue:201.0/255.0 alpha:1.0];
}
On this view when I click a button , I am presenting MFMailComposeViewController modally. When I present MFMailComposeViewController modally, navigation bar same color as set in viewWillAppear. I want default blue color as Apple told that don't customize this view. Here is my code which I have tried
Code 1:
-(void)sendEmailWithWithRecipients:(NSArray*)recipients andData:(NSData*)data {
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
self.navigationController.navigationBar.tintColor = nil;
[self presentModalViewController:mailComposeViewController animated:YES];
[mailComposeViewController release];
}
else {
[self showAlertWithTitle:#"Alert" andMessage:#"Can not send email. Please check your email settings."];
}
}
But above code is not working for tint color
Code 2: Set tint color in viewWillDisappear
-(void)viewWillDisappear:(BOOL)animated {
NSLog(#"%s",__PRETTY_FUNCTION__);
self.navigationController.navigationBar.tintColor = nil;
[super viewWillDisappear:animated];
}
Code 2 also not working.
But this is working fine in iOS5 without setting tintColor = nil while presenting MFMailComposeViewController modally & in viewWillDisappear. Its not working iOS 4.x
Anyone have solution for this? Thanks.
You can customize the navigationbar's tint color by accessing yourController's(ViewController which you are presetnting) topViewController.
Ex :
[self presentModalViewController:yourController animated:YES];
yourController.topViewController.navigationController.navigationBar.tintColor =
[UIColor (Your Color)];
Try setting the navigation bar style rather than the tint color. Tint color and bar style have slightly different side effects, so while I don't completely understand your needs, it might be exactly what you're looking for.
[self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
or
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
And make sure you do this within the context of the modal view controller, not the previous view controller.
Instead of nil try this [UIColor ClearColor];

Resources