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]]];
Related
I want to add text from my database to a UIWebView, but I have an error I can't deal with.
in my .h:
#import <UIKit/UIKit.h>
#interface readNotice : UIViewController {
IBOutlet UILabel *message;
IBOutlet UIWebView *body;
}
#property(nonatomic, retain)IBOutlet UILabel *message;
#property(nonatomic, retain)IBOutlet UIWebView *body;
-(void)getNoticeData:(NSString *)noticeID:(NSString *)noticeTitle;
#end
In the .m:
#synthesize message,body;
-(void)getNoticeData:(NSString *)noticeID:(NSString *)noticeTitle {
//some taks not useful for this code
NSString *bodyText = [dict objectForKey:#"introtext"];
[body loadHTMLString: bodyText];
}
The error I get:
No visible #interface for 'UIWebView' declares the selector 'loadHTMLString:'
why is this happening? Thank you in advance
try using like this
NSString *html = #"Should be halfI wish the answer were just 42";
[webView loadHTMLString:html baseURL:nil];
The correct call would be loadHTMLString:baseURL:
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 have a UIWebView object declared in my view controller and I want to make it load a different page when the app recieves a notification while the app is running using application:didRecieveRemoteNotification:. I'm having trouble accessing the object from inside the appDelegate.
Any simple way to do this?
this is how I declare my web view
.h
IBOutlet UIWebView *webView;
#property (nonatomic, retain) UIWebView *webView;
.m
#synthisize webView;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:currentPath]]];
this is not the best idea to show the web view from outside the controller. Just add method like this to controller:
-(void) loadFromPath:(NSString*) path {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: path]]];
}
and call it in your app delegate when you need.
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...
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];