Archive

Archive for July, 2010

UIWebView in Action – iPhone Application Development

July 28, 2010 Leave a comment

Usually we use UIWebView to load web pages. But i faced some problems that was really scared for me. Visited couple of forums, talked to some guyz and they really helped me to stuck out of that problem.

Okay, let me share it.  If you need to show a hyperlink or have to show a large text with some captions (i mean something like headline) what will you do???Don’t panic couple of solutions are waiting for you.

UIWebView as hyperlink

First, you can use a custom label and a button to trgiger that action. You can also get help from the famous Threee20 project. But i found UIWebview very much useful. You have to place that UIWebView in the exact position and then use a transparent button to do something. Here is some  code snnipet

myWebView.frame = prefableFrame;  // any preferable frame

NSString *linkString = @"WWW.makboney.wordpress.com";

linkString  =[@" "linkString];linkString =[linkString stringByAppendingString:@" "];

[myWebView  loadHTMLString:linkString baseURL:nil];

//hidden button to trigger actionhiddenButton = [UIButton buttonWithType:UIButtonTypeCustom];

hiddenButton.frame = myWebView.frame;

hiddenButton.backgroundColor = [UIColor clearColor];

[hiddenButton addTarget:self action:@selector(buttonPressed)                                forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:hiddenButton];

UIWebView to show html text or big text containing  caption , bullet marks or somthing like that

When you need to display large text into label with some caption,bullet marks and also managed couple of other issues. In that case  i suggest you to use  UIWebView. For this you need to do some preprocessing  of the big text such as including tags into proper place. And now its easy. Follow the  bellow code snippet.

NSString *htmlTextString;

htmlTextString  =[@"" stringByAppendingString:[appDelegate modifiedString: bigtext]];

[descLabel loadHTMLString:htmlTextString baseURL:nil];
Follow

Get every new post delivered to your Inbox.