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;
Related
I need to implement a login UI in my tvOS application, but I don't want to use UIAlertController for the text input. Instead of this I want to implement a text input UI similar to the iCloud Sign In in the Settings app without any additional UITextFields.
You can do it with a table view populated with some cells with embedded text fields.
These UITextField than becomes input responder like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// my UITableViewCell extended with UITextField
TextFieldCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.textField becomeFirstResponder];
}
place text field on a view (If you dont wont to show it, place it out of borders)
in viewController code add inputAccesoryView method
When you need to show your input view - call [self.loginTextField becomeFirstResponder];
I found that input accesory view located in top right corner of standart input view, so code for it should look like this:
-(UIView *)inputAccessoryView {
if (!inputAccessoryView) {
CGRect accessFrame = CGRectMake(0, 0, 1920, 200);
inputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(-500, -100, 1000, 100)];
titleLabel.font = [UIFont systemFontOfSize:59];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = #"Login";
titleLabel.textAlignment = NSTextAlignmentCenter;
[inputAccessoryView addSubview:titleLabel];
descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(-500, 0, 1000, 100)];
descriptionLabel.font = [UIFont systemFontOfSize:29];
descriptionLabel.textColor = [UIColor whiteColor];
descriptionLabel.text = #"Enter your E-mail or Login";
descriptionLabel.textAlignment = NSTextAlignmentCenter;
[inputAccessoryView addSubview:descriptionLabel];
}
return inputAccessoryView;
}
It work for me.
I am using CoreTextView on iOS to render an html file in a UIScrollview that is set up programmatically. As soon as the html file exceeds a certain length, the text no longer renders. It does not seem to be a problem with:
Memory. NSLog displays the entire NSAttributedString no matter how long it is.
A formatting error in the html file. I was able to render the entire file in pieces.
If I put in a very large height for the frame, same thing: empty screen and no errors to troubleshoot. I suspect that the issue has something to do with calculating file size and maybe... font line size? Stumped. Incidentally, if I enter a custom font, it is ignored and only the default Helvetica is displayed. Font SIZES, however, render correctly. Any help on getting the entire file to display would be much appreciated!
My code:
m_coreText = [[CoreTextView alloc] initWithFrame:CGRectZero];
m_coreText.backgroundColor = [UIColor clearColor];
m_coreText.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
NSString* html = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"terms" ofType:#"html"] encoding:NSUTF8StringEncoding error:NULL];
m_coreText.attributedString = [NSAttributedString attributedStringWithHTML:html renderer:^id<HTMLRenderer>(NSMutableDictionary* attributes) {
CustomRenderer* renderer=[[CustomRenderer alloc] init];
renderer.type=attributes[#"type"];
renderer.size=CGSizeMake(16, 16);
return renderer;
}];
m_coreText.frame = CGRectMake(0, 0, self.view.bounds.size.width, [m_coreText sizeThatFits:CGSizeMake(self.view.bounds.size.width, MAXFLOAT)].height);
UIScrollView* scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scroll.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
scroll.contentSize=m_coreText.frame.size;
[scroll addSubview:m_coreText];
[self.view addSubview:scroll];
I have a form sheet segue that should display hard-coded html page.
Now I have a two part problem first problem is
<CENTER><H1>A Simple Sample Web Page</H1><H4>By Frodo</H4>
<H2>Demonstrating a few HTML features</H2></CENTER>
is displayed like
I can change <CENTER>tag to <left> in that case it works but it limits my options. How can I display this content In the middle of the screen without alignment issues?
Second part of the question is How can I embed a color or a link to content. On line ""FFFFFF">\n" I get the error that says Expected ':' and on line "<a href="http://somegreatsite.com">\n" Half of the line is green which is seems like comment on the screen that means it will not executed by XCode
My full code is like :
- (void) createWebViewWithHTML{
//create the string
NSMutableString *html = [NSMutableString stringWithString: #"<html><head><title></title></head><body style=\"background:transparent;\">"];
//continue building the string
[html appendString:#"<BODY BGCOLOR="
""FFFFFF">\n"
"<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM">
"</CENTER> \n"
"<HR>\n"
"<a href="http://somegreatsite.com">\n"
"Link Name</a>\n"
"is a link to another nifty site\n"
"<H1>This is a Header</H1>\n"
"<H2>This is a Medium Header</H2>\n"
"Send me mail at <a href="mailto:support#yourcompany.com">\n"
"support#yourcompany.com</a>.\n"
"<P> This is a new paragraph!\n"
"<P> <B>This is a new paragraph!</B>\n"
"<BR> <B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>\n"
"<HR>\n"];
[html appendString:#"</body></html>"];
//instantiate the web view
webView = [[UIWebView alloc] initWithFrame:self.view.frame];
//make the background transparent
[webView setBackgroundColor:[UIColor clearColor]];
//pass the string to the webview
[webView loadHTMLString:[html description] baseURL:nil];
//add it to the subview
[self.view addSubview:webView];
}
Edit::
Added story board picture
So how can I make correct alignment and embed color/link correctly?
Check if your UIWebView has the right size. It seems to be bigger than the screen.
Place a \ before any " in your hard-coded string.
e.g.:
NSString *testString="This is a \"Test\"";
results in
This is a "Test"
Hope this helps
I have an item detail view which I would like to use for two purposes:
1) to create a new item
2) to edit an existing item
When editing, the view will be pushed onto the navigation stack, getting the nav bar from it's parent.
On item creation, I want to present the view modally, but still have a navigation bar at the top, with "Done" and "Cancel" buttons.
What I don't want is to ever see the view with two nav bars, or none.
How would I implement this?
In order to accomplish this I:
Removed the nav bar from my view.
When launching modally, first created a nav controller, and then displayed the nav controller modally with my view as the root view (even though I didn't plan on pushing anything else onto the stack). So changed this:
StoreDetailView *storeDetailView = [[StoreDetailView alloc] initWithNibName:#"StoreDetailView" bundle:nil];
// ... configure the view, including setting delegate...
[self presentViewController:storeDetailView animated:YES completion: nil];
to this:
StoreDetailView *storeDetailView = [[StoreDetailView alloc] initWithNibName:#"StoreDetailView" bundle:nil];
// ... configure the view, including setting delegate...
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:storeDetailView];
[self presentViewController:navController animated:YES completion: nil];
And then in the StoreDetailView, determined what the nav bar should look like based on whether the delegate was set:
if (self.delegate == nil) {
self.navigationItem.rightBarButtonItem = [self editButtonItem];
} else {
[self setEditing:TRUE];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(done:)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(cancel:)];
}
When I use the following code to insert a view on top of a split view, I am getting orientation problems.
Here is the code I use,
[window addSubview:aSplitViewController.view];
[window insertSubview:aViewController.view aboveSubview:aSplitViewController.view];
What happens here is that the view controller ( which contains labels and buttons) loads in landscape mode while its components load in portrait mode...
I feel that the window insertSubview is creating this problem because when I used [window addSubview:aViewController.view] the view is getting displayed properly in landscape mode with its components in landscape mode as well...
Here is the code which I feel is giving me the problem
In my App Delegate
- (void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
// First tabbbar item
// detail view
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *navDetailView = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
navDetailView.hidesBottomBarWhenPushed = YES;
// root view
rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.detailViewController = detailViewController;
rootViewController.navigationItem.title = #"List";
UINavigationController *navRootView = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
navRootView.hidesBottomBarWhenPushed = YES;
navRootView.navigationBar.barStyle = UIBarStyleBlackTranslucent;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem.title = #"Face Sheet";
splitViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
splitViewController.navigationItem.title = #"Face Sheet";
splitViewController.viewControllers = [NSArray arrayWithObjects:navRootView, navDetailView, nil];
splitViewController.delegate = detailViewController;
splitViewController.hidesBottomBarWhenPushed = YES;
[controllers addObject:splitViewController];
// Second tabbbar item
scoreViewController = [[ScoreCardViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
scoreViewController.tabBarItem.title = #"Score Card";
scoreViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
scoreViewController.navigationItem.title = #"Score Card";
[controllers addObject:scoreViewController];
tabBarController.viewControllers = controllers;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Create tabbar
tabBarController = [[UITabBarController alloc] init];
//tabBarController.delegate = self;
// Set window
[window addSubview:splashController.view];
[window insertSubview:tabBarController.view belowSubview:splashController.view];
[self.window makeKeyAndVisible];
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
return YES;
}
and here is the code in my SplashScreenView
- (IBAction) proceedButtonClick:(id)sender
{
// Initialize loginpopview
PhysicianLoginViewController *loginViewController = [[PhysicianLoginViewController alloc] init];
popOverController = [[UIPopoverController alloc] initWithContentViewController:loginViewController];
popOverController.popoverContentSize = CGSizeMake(350, 200);
popOverController.delegate = self;
// Set a notification to dismiss it later
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(loginViewControllerDone:) name:#"loginViewControllerDone" object:popOverController.contentViewController];
// Present popover
if ([popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
else
{
[popOverController presentPopoverFromRect:CGRectMake(485, 600, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
// Dismiss popview controller and setup the tabbar
- (void)loginViewControllerDone:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Button in content view controller was tapped, dismiss popover...
[self.popOverController dismissPopoverAnimated:YES];
// remove subview
[self.view removeFromSuperview];
// set tabbar
i3EAppDelegate *appDelegate = (i3EAppDelegate *) [[UIApplication sharedApplication]delegate];
[appDelegate makeSplitViewController];
}
It would be great if someone could point out where I am going wrong. I have been stuck with this problem for quite a few days and I have tried everything that comes to my mind...
Your problem is that the rotation handling of UIWindow and UIViewController just isn't designed to work that way. Quoth the documentation:
In an iOS application, the window object does much of the work associated with changing the current orientation. However, it works in conjunction with the application’s view controllers to determine whether an orientation change should occur at all, and if so, what additional methods should be called to respond to the change. Specifically, it works with the view controller whose root view was most recently added to, or presented in, the window. In other words, the window object works only with the frontmost view controller whose view was displayed using one of the mechanisms described in “Presenting a View Controller’s View.”
This paragraph is somewhat vague and contradictory (is it the most recently added view controller, or the controller for the topmost view?), and in practice doesn't seem to necessarily match observations. The bottom line is that adding multiple views to a UIWindow will screw up the automatic rotation handling.
You should change your code to use presentModalViewController:animated: (maybe with modalPresentationStyle set to UIModalPresentationFormSheet) or a UIPopoverController instead of adding multiple subviews to the window.
Try:
[aViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];