how to disable horizontal scroll for a uiwebview? - iphone

I created a sample in which i imported a word(.docx)on to the uiwebview and displayed.I got the output but i don't want to display the horizontal scroll bar and the vertical scroll also working not properly i can see the black space behind the webview when i scroll it vertically.
Here is my code:
#import <UIKit/UIKit.h>
#interface userguideLinesNewViewController : UIViewController {
IBOutlet UIWebView *webView;
}
#property (nonatomic,retain) UIWebView *webView;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews;
#end
#import "userguideLinesNewViewController.h"
#implementation userguideLinesNewViewController
#synthesize webView;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"BTBP CLARITY SKIN ADVISORuser.docx" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViews loadRequest:request];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadDocument:#"BTBP CLARITY SKIN ADVISORuser.docx" inView:self.webView];
}

You could check others topics about this : Stop UIWebView from "bouncing" vertically? :-)
There isn't a method like in UIScrollView. But there is some kind of way to achieve your goal ;-)
Here is my way.
- (void)disableBounce {
for (id subview in self.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
}
Enjoy...

Related

Load Webview in different view in iOS Programming

I have been programming an Web browser app for iOS and stumbled upon an issue. At first my search text field and web view where in the same view (Everything was fine :). When I put the web view in an different view the web view wouldn't load up the page and stay blank. So the issue is the web view will not load in a different view (will work if text field and web view are in the same view).
My Code:
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface ViewController ()
#end
#implementation ViewController
#synthesize searchButton;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
}
-(IBAction)SearchButton:(id)sender {
NSString *query = [searchField.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.google.com/search?q=%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
ViewController *WebView = [self.storyboard instantiateViewControllerWithIdentifier:#"WebView"];
[self presentViewController:WebView animated:YES completion:nil];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
The SearchButton method refers to a webView in the current class, but it's the new ViewController (you call it WebView) which is about to be presented and that should contain a UIWebView. So the UIWebView on the presented view controller is never getting to loadRequest.
Create a subclass of UIViewController to contain your web view. (call it something like MyWebViewController) It should have a property called urlString. Make sure to change the class of the view controller you currently have painted in storyboard to MyWebViewController.
The SearchButton method should look like this:
// renamed to follow convention
- (IBAction)pressedSearchButton:(id)sender {
NSString *query = [searchField.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSString *urlString = [NSString stringWithFormat:#"http://www.google.com/search?q=%#", query];
// remember to change the view controller class in storyboard
MyWebViewController *webViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"WebView"];
// urlString is a public property on MyWebViewController
webViewController.urlString = urlString;
[self presentViewController:webViewController animated:YES completion:nil];
}
The new class can form the request from the urlString...
// MyWebViewController.h
#property (nonatomic, strong) NSString *urlString;
#property (nonatomic, weak) IBOutlet UIWebView *webView; // be sure to attach in storyboard
// MyWebViewController.m
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSURL *url = [NSURL URLWithString:self.urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}

how to justify text in UITextView in iphone?

how to justify text in UITextView
I try this like this but this code do not give any output.
[web loadHTMLString:[NSString stringWithFormat:
#"<html><body><p align=\"justify\"> %# </p> </body></html>",
[dict1 objectForKey:#"services_description"]] baseURL:nil];
textView.textAlignment = NSTextAlignmentJustified;
This only works on iOS 6 and above
I suggest You to use WebView Because justified aligment for text you only have center, left and right by UITextView.
IF You Want to Use UIWebView then set in
className.h
#interface className : UIViewController {
IBOutlet UIWebView *webviewName;
}
#property (nonatomic, retain) UIWebView *webviewName;
className.m
[webviewName loadHTMLString:[NSString stringWithFormat:#"<div align='justify'>%#<div>",TEXT_set] baseURL:nil];
You can justify the text in the UITextView by choosing the alignment from the utilities
You can Create a HTML Page with propertext allignment and then Load the Local HTML page in a Webview.
webView = [UIWebView alloc] init];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"test" ofType:#"html"]isDirectory:NO]]];

Open Link in UIWebView in Safari

I am working on an app that receives a feed that I display in a UIWebView. The feed has embedded links that I want to open in Safari instead of thew WebView. I have looked over several other questions that are posted here. I am not sure what I am missing, but I think it is something simple. Here are my .h and .m files
#import
#class BlogRss;
#interface EnduranceDailyWorkoutViewController : UIViewController {
IBOutlet UIWebView * descriptionTextView;
BlogRss * currentlySelectedBlogItem;
}
#property (nonatomic, retain) UIWebView * descriptionTextView;
#property (readwrite, retain) BlogRss * currentlySelectedBlogItem;
#end
#import "EnduranceDailyWorkoutViewController.h"
#import "BlogRss.h"
#implementation EnduranceDailyWorkoutViewController
#synthesize descriptionTextView = descriptionTextView;
#synthesize currentlySelectedBlogItem = currentlySelectedBlogItem;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *html = [NSString stringWithFormat:#"%# %#",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
[descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}
-(BOOL)webView:(UIWebView *)descriptionTextView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (UIWebViewNavigationTypeLinkClicked == navigationType) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
return YES;
}
Using Interface Builder I have linked the IBOutlet and the UIWebView. Please let me know what I am missing. I have put break points in the webView section but the code never hits there so it is almost like something is not linked correctly in IB.
You need to ensure that the UIWebView's delegate is set to your controller. You can do this in interface builder, or you can modify your viewDidLoad method:
- (void)viewDidLoad {
[super viewDidLoad];
// add this line to set the delegate of the UIWebView
descriptionTextView.delegate = self;
NSString *html = [NSString stringWithFormat:#"%# %#",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
[descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}

I can't get UIWebViewDelegate to work

I'm trying to implement a UIWebViewDelegate in my application and I cannot for the life of me get it to work. I would really appreciate a second set of eyes on this.
I know the name MapViewController is confusing, but the WebView is controlling a map (not UIMapView).
Here's the bulk of the code:
MapViewController.h
#import <UIKit/UIKit.h>
#import <UIKit/UIWebView.h>
#interface MapViewController : UIViewController<UIWebViewDelegate> {
IBOutlet UIWebView *webView;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#end
MapViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
webView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"map" ofType:#"html"]isDirectory:NO]];
[webView loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(#"Done loading.");
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"hi");
return NO;
}
- (void)dealloc {
webView.delegate = nil;
[webView release]
[super dealloc];
}
Thanks for any help!
Does the initial page you're loading actually display? Are you sure you connected your webview in Interface Builder?
go interface builder , connect the delegate to the file's owner , then it should work.
Open Interface Builder
Right click on the Web View object
Drag the delegate onto files owner.
Things to check:
if map.html is in the bundle. Put it on the root of the bundle, not on resources.
if it is, right click on it, and choose get info. Verify on TARGETS if the target is checked for the file.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"hi");
return YES; // for all supported oreintation.
}

UIWebview does not show up into UINavigationController

I have a tabBar application. In the first tab, I have a navigation bar. In this navigation bar I have a table view. When the user clicks a cell of the table, it goes to another table view, and when the user clicks a cell in that table, it goes to a webview to open a web page.
Basically, it goes fine until opening the webview. In the webview, viewDidLoad is called and seems to work properly. However, webViewDidStartLoad is never called and the web page never shows up.
I am not using IB. I build the UITabBarController in the AppDelegate, where I also assign an instance of my UINavigationController for each tab.
I call the webview from the second UITableViewController as follows:
rssWebViewController = [[webViews objectAtIndex: indexPath.row] objectForKey:#"controller"];
[[self navigationController] pushViewController:rssWebViewController animated:YES];
I have checked that the navigationController is there and it seems just fine.
The viewDidload of my webview is as follows:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = self.storyUrl;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[self rssWebView] setDelegate: self];
[[self view] addSubview:[self rssWebView]];
[rssWebView loadRequest:requestObj];
self.rssWebView.scalesPageToFit = YES;
self.rssWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
}
The web view controller interface is defined as follows:
#interface RSSWebViewController : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *rssWebView;
IBOutlet NSString *storyUrl;
IBOutlet NSString *feedName;
}
#property (nonatomic, retain) IBOutlet UIWebView *rssWebView;
#property (nonatomic, retain) IBOutlet NSString *storyUrl;
#property (nonatomic, retain) IBOutlet NSString *feedName;
#end
Any help is greatly appreciated.
ok, I found out, I had to initiate my webview with a frame in viewDidLoad:
rssWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];