UITabBarItem in landscape UITabBar in iOS 11 - uitabbar

I'm programmatically adding tab bar items to a tab bar however when the tab bar is in landscape mode the tab bar items don't change to the new landscape style with the icon on the left and text on the right. How do I update the style of my tab bar items when the tab bar is in landscape mode for iOS 11?
Here is some code as requested.
UITabBar *tabBar = [UITabBar new];
NSInteger tag = 0;
NSMutableArray<UITabBarItem *> *items = [NSMutableArray new];
for(UIViewController *viewController in viewControllers)
{
NSString *title = viewController.title;
UIImage *image = [UIImage imageNamed:title];
UITabBarItem *tab = [[UITabBarItem alloc] initWithTitle:title image:image tag:tag++];
[items addObject:tab];
}
tabBar.items = items;
[self.view addSubview:tabBar];

It should work automatically when changing the orientation to landscape, I tried and it is working in Xcode 9.0, No additional code required to be done when you use storyboard based TabBar Controller or your custom TabBar Controller.
While googling I found that some one reported the same issue in one of the library Here
They fixed the issue by setting up the frames for label and image while orientation changes. so, please have a look here if that can be helpful.
https://github.com/eggswift/ESTabBarController

Related

Adjusting the height of a wkwebview programmatically

This is my first question on Stack Overflow. I just started learning swift programming and got sucked into something.
I followed IAP tutorials on YouTube and successfully implemented AdMob banners and interstitial ads in my app. I was also able to turn off ads using the IAP. My question is:
I have a view in which I have two UI elements (WKWebViewand a GADBannerView). The WKWebView element covers 90% of the screen starting from x:0,y:0, whereas the GADBannerView element covers 10%. I turned off ads and hid the GADBannerView element using IAP.
Now I want to dynamically/programmatically adjust the WKWebView size to fill the entire screen, i.e 100%. In other words, I want the WKWebView element to extend over the hidden GADBannerView element.
This is because hiding the GADBannerView leaves a blank field which is not cool to the view and the WKWebView looks truncated.
Please note that neither of the views are subviews. Both are independent views added separately. I understand that I can initially make the web view fill entire screen, add the GADBannerView on top of it, and when I remove ads and hid the GADBannerView, the web view will fill screen. That is not what I want because some content of the web view can not be seen using this approach. If I have a button at the end of HTML page that loads on the web view, this button can not be clicked because it will always be behind the gad banner view even when scrolling reached the bottom. Yes, you can scroll and hold to see the button, but once you release it, it will go back down.
So as a recap, I have two separate views and want to hid one and extend the length of the other to cover the entire screen.
Please tell me how to achieve that.
thirdBannerView.isHidden = true //Hide the banner view
//then code below to increase the size of the web view to equal device //screen width and height i.e full screen.
func webViewDidFinishLoad(webView: WKWebView) {
//let screenBounds = UIScreen.main.bounds
// let heightq = screenBounds.height
//let widthq = screenBounds.width
//webView.frame.size.height = heightq
//webView.frame.size = webView.sizeThatFits(CGSize.zero)
//webView.frame = CGRectMake(0, 0, widthq, heightq);
webView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
}
This code is not effective at all as nothing changes. Please let me know how to achieve this.
This particular scenario looks promising for applying UIStackview. Add your two view ( WKWebview and GADBannerView). apply fixed height for the GADBannerview. Whenever necessary just hide the GADBannerview.
Sample code
class StackviewController : UIViewController {
let stackview: UIStackView = {
let view = UIStackView()
view.axis = .vertical
view.distribution = .fill
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// Your WKWebview here
let sampleWKWebView: UIView = {
let view = UIView()
view.backgroundColor = .red
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// Your GADBannerView here
let sampleGADBannerView: UIView = {
let view = UIView()
view.backgroundColor = .green
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
}
func setupViews() {
view.addSubview(stackview)
stackview.addArrangedSubview(sampleWKWebView)
stackview.addArrangedSubview(sampleGADBannerView)
NSLayoutConstraint.activate([
stackview.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0),
stackview.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0),
stackview.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0),
stackview.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0),
sampleGADBannerView.heightAnchor.constraint(equalToConstant: 100.0)
])
// Enable this line to hide the GADBannerView
// sampleGADBannerView.isHidden = true
}
}
Here is the output
I use two UIView to represent the WKWebView & GADBannerView. In the sample code uncomment the following to hide the bottom banner like green view.
sampleGADBannerView.isHidden = true

How to solve range slider zoom in ios

I am using a range slider in my site. site link . click on the options on the header and you will see the range slider. its ion range slider jquery plugin.
Its working good on desktop and android. But in ios, when i click on the range slider to change its automatically zoom which I don't want. i just need it plain as desktop.
and one more problem in ios. the search bar border has no radius but it shows radius on ios.
Can you please help me.
Thanks in advance.
Search Bar Radius:
for (UIView *searchBarSubview in [mySearchBar subviews])
{
if ([searchBarSubview conformsToProtocol:#protocol(UITextInputTraits)])
{
#try
{
[(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleRoundedRect];
}
#catch (NSException * e)
{
// ignore exception
}
}
}
(void)viewDidLoad
{
[super viewDidLoad];
UITextField *txfSearchField = [search valueForKey:#"_searchField"];
[txfSearchField setBackgroundColor:[UIColor whiteColor]];
[txfSearchField setLeftView:UITextFieldViewModeNever];
[txfSearchField setBorderStyle:UITextBorderStyleRoundedRect];
txfSearchField.layer.borderWidth = 8.0f;
txfSearchField.layer.cornerRadius = 20.0f;
txfSearchField.layer.borderColor = [UIColor clearColor].CGColor;
// Do any additional setup after loading the view, typically from a nib.
}

Slide view controller menu and status bar issue with IOS7

I have a slide view controller setup.
When viewing the app in IOS7 the status bar is shown and translucent so it is shown with the content.
Is there something I should be doing to offset the content below the status bar for this specific View Controller in my storyboard?
Awarded answer to #Idan for the suggestion but as this is a table view controller had to accomplish differently:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7")) {
self.tableView.frame = CGRectMake(0, 20, self.tableView.frame.size.width, self.tableView.frame.size.height-20);
}
}
I've solved it by introducing setting the table header view as a 20 point height view.
This code in viewDidLoad
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, self.tableView.frame.size.width, 20.f)];
headerView.backgroundColor = [UIColor whiteColor];
self.tableView.tableHeaderView = headerView;
Two different methods (depands on what you are trying to do):
Add this value to plist: "View controller-based status bar appearance" and set it to "NO". then you can code whatever you want (setStatusBarHidden etc.)
If you just want to move the view when it's iOS7 (status bar is above), in interface builder -> attribute inspector -> set delta y to -20 (so it would be below status bar).

How to make small content fill UIWebView?

I have created a UIWebView, banner sized, which is a subview of my UITabBar. I have placed it right on top of the tab bar. I know I have done this correctly since loading for example google.com gives me the exact appearance I am after.
For my banner though, I want to load a picture from my Google Drive account. This appears to be to small because it does not fill the web view when I am running on iPad and I therefore end up with an annoying space between the banner and the tab bar, respectively between the banner and the right screen edge.
Is there any way I can scale the content to exactly fit the web view?
EDIT: The code which I am using to show the image in the web view:
// Tab bar initialization
TabbeBarreViewController *tabViewController = [[TabbeBarreViewController alloc] init];
[tabViewController setViewControllers:viewControllers];
// Banner set up
CGSize tabBarSize = [[tabViewController tabBar] bounds].size;
UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - tabBarSize.height - tabBarSize.width/4.0, tabBarSize.width, tabBarSize.width/4.0)];
[wv setOpaque:NO];
[wv setBackgroundColor:[UIColor clearColor]];
[wv setHidden:YES];
[[wv scrollView] setScrollEnabled:NO];
[wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"https://docs.google.com/drawings/d/11MLox_3u0iqNwk3UdmCd4YHWYMSLxzbkyfgQjUJuSko/pub?w=606&h=152"]]];
[[tabViewController view] addSubview:wv];
[wv setDelegate:self];
// Presenting tab bar with subview banner
[self presentViewController:tabViewController animated:YES completion:nil];
and
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
CGSize contentSize = theWebView.scrollView.contentSize;
CGSize viewSize = self.view.bounds.size;
float rw = viewSize.width / contentSize.width;
theWebView.scrollView.minimumZoomScale = rw;
theWebView.scrollView.maximumZoomScale = rw;
theWebView.scrollView.zoomScale = rw;
theWebView.hidden = NO;
}
You can try small piece of HTML code here to load content into the webview as below
NSString *HTML=#"<html><body padding=\"0\"><img src=\"imgurl\" width=\"100%\" height=\"100%\"/></body></html>";
[self.webview loadHTMLString:HTML baseURL:nil];
Edit
Or, you can add a UIImageView instead like below
UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"YOURIMAGEURL"]]];
self.imagView.image=image;

Can I use two xibs with one viewcontroller - re: porting to iPhone 5

I just submitted my first app to the app store (yay it was just approved!). I now want to update it to work with (look nicer on) the larger iPhone 5 screen. I don't intend to change anything other than to change the layout a bit for the larger screen.
NOTE: I don't want to have my current xib stretched.
Is it possible to create two xib files (ie: copy my current xib file for the main screen) and hook them both into the view controller and have it so that when the app launches, the app detects if there is an iPhone 5 screen or an earlier screen. Then, depending on which device it is, show the user a different screen.
I intend for underlying app to remain the same. All I want is to present a slightly different (taller) screen for iPhone 5 users with a few buttons/items moved around for the new layout. I otherwise won't be adding or removing anything from the interface.
This SO question/answer shows how to switch between an iPhone or iPad view. So to does this one. Both are helpful but I don't know how to modify this for the circumstance where the user is using an iPhone 5 with a larger screen or an iPhone 4S and below. Also, they assume two view controllers. I only want ONE view controller since absolutely NOTHING in the view controller logic changes - only the placement of the objects on the screen change and that is all done in the XIB.
I should think the answer should be that the view controller iteslf assesses what device it is running on then presents the appropriate xib? Yes? No?
If so, how would I go about this?
[Revised with Complete Answer on : Oct 7, 2012]
After significant research I found the answer, partly on this SO page (which shows how to detect which iPhone version your app is running on) and partly this SO page (showing how to have two xib's share the same 'File's Owner'. The final piece of the puzzle (loading separate xib's via the loadNibNamed: method) I found in chapter 10 of The Big Nerd Ranch's excellent iOS Programming text. Here's how:
Create a second xib (File, New..., File, select 'User Interface', select 'Empty' and save it. This creates the new xib. In the example below, my classic xib (for 3.5" iPhones) was named TipMainViewController.xib. I saved the new iPhone 5 xib with the name 'TipMainViewController-5.xib'
Make that new xib's 'File's Owner' the same ViewController as your existing xib. To do this, in the new xib file, select 'File's Owners'. Then in the 'Identity Inspector' select the existing View Controller as the Custom Class. In my case I selected 'TipMainViewController'.
Drag a new UIView onto the new xib's empty canvas. In the new UIView's attribute inspector set the 'Size' attribute to 'Retina 4 Full Screen'
Select all the contents in the existing 'Classic' 3.5" xib - eg: all your controls, buttons, selectors, labels etc. Copy them and paste them into the new iPhone 5 xib. Resize/move etc. them to optimize for the iPhone's 4" display.
Make all the connections to/from File's Owner as you did when you created your original xib.
Finally, in the 'viewDidLoad' method of your 'single' ViewController, insert the following logic (using your nib/xib names of course):
- (void)loadView
{
[super viewDidLoad];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
[[NSBundle mainBundle] loadNibNamed:#"TipMainViewController" owner:self options:nil];
}
if(result.height == 568)
{
// iPhone 5
[[NSBundle mainBundle] loadNibNamed:#"TipMainViewController-5" owner:self options:nil];
}
}
}
Here is a simple, working code sample for your view controller that shows how to load myXib-5.xib on the iPhone 5 and myXib.xib on iPhones/iPods predating the iPhone 5:
- (void)loadView
{
if([[UIScreen mainScreen] bounds].size.height == 568)
{
// iPhone 5
self.view = [[NSBundle mainBundle] loadNibNamed:#"myXib-5" owner:self options:nil][0];
}
else
{
self.view = [[NSBundle mainBundle] loadNibNamed:#"myXib" owner:self options:nil][0];
}
}
It assumes that you are only targeting the iPhone and not the iPad, to keep it simple.
The XIB's file owner's class property should also be set to the view controller that contains loadView.
Code in answer was helpful, but I needed something that worked better for universal apps (iphone/ipad).
In case someone else needs the same thing, here's something to get you started.
Say you built a universal app using the nib/xib naming standards for ios for view controllers that have xibs with the same name:
The two built-in defaults for autoloading xibs when providing no name is passed to initWithNibName:
ExampleViewController.xib [iphone default when nib named empty for Retina 3.5 Full Screen for classic layouts iphone 4/4s etc...]
ExampleViewController~ipad.xib [ipad/ipad mini default when nib named empty]
Now say you need custom xibs for the iphone 5/5s in IB using Retina 4 Full Screen option, i.e., you don't want the 3.5 xibs displaying for any 568h devices.
Here's the custom naming convention using a category approach:
ExampleViewController-568h.xib [iphone non default/custom naming convention when nib name empty for Retina 4 Full Screen (568h)]
Instead of overriding the built-in naming defaults, use a category to help set the right xib for the controller.
https://gist.github.com/scottvrosenthal/4945884
ExampleViewController.m
#import "UIViewController+AppCategories.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
nibNameOrNil = [UIViewController nibNamedForDevice:#"ExampleViewController"];
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Do any additional customization
}
return self;
}
UIViewController+AppCategories.h
#import <UIKit/UIKit.h>
#interface UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name;
#end
UIViewController+AppCategories.m
// ExampleViewController.xib [iphone default when nib named empty for Retina 3.5 Full Screen]
// ExampleViewController-568h.xib [iphone custom naming convention when nib named empty for Retina 4 Full Screen (568h)]
// ExampleViewController~ipad.xib [ipad/ipad mini default when nib named empty]
#import "UIViewController+AppCategories.h"
#implementation UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if ([UIScreen mainScreen].bounds.size.height == 568)
{
//Check if there's a path extension or not
if (name.pathExtension.length) {
name = [name stringByReplacingOccurrencesOfString: [NSString stringWithFormat:#".%#", name.pathExtension] withString: [NSString stringWithFormat:#"-568h.%#", name.pathExtension ]
];
} else {
name = [name stringByAppendingString:#"-568h"];
}
// if 568h nib is found
NSString *nibExists = [[NSBundle mainBundle] pathForResource:name ofType:#"nib"];
if (nibExists) {
return name;
}
}
}
// just default to ios universal app naming convention for xibs
return Nil;
}
#end