CraigBellamy
CraigBellamy

Reputation: 27

add UIWebView programmatically to UIImageView

I would like to be able to add zoom functionality to UIImage and believe the best way is to embed within UIWebview. Would someone be able to help me achieve this?

- (void)viewDidLoad
{
[super viewDidLoad];

// image
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 70, IMGSIZE.width, IMGSIZE.height)];
[self.imageView setClipsToBounds:YES];
self.imageView.layer.borderColor = kITBarTint.CGColor;
self.imageView.layer.borderWidth = 1.0;
self.imageView.layer.cornerRadius = 15.0;
self.imageView.layer.shadowColor = [UIColor blackColor].CGColor;
self.imageView.layer.shadowOffset = CGSizeMake(5, 5);
self.imageView.layer.shadowRadius = 10;

[self.controller.view addSubview:self.imageView];

// activity indicator
CGRect frame = CGRectMake(roundf(IMGSIZE.width / 2) + self.imageView.frame.origin.x, roundf(IMGSIZE.height /2) + self.imageView.frame.origin.y, 0, 0);
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[_activityIndicator setFrame:frame];
[_activityIndicator startAnimating];
[self.controller.view addSubview:_activityIndicator];


}

Upvotes: 0

Views: 1089

Answers (2)

iProRage
iProRage

Reputation: 424

Try adding this to your viewDidLoad method,

scrollView.minimumZoomScale = 0.4;
scrollView.maximumZoomScale = 4.0;
scrollView.delegate = self;
[scrollView setZoomScale:scroll.minimumZoomScale];

Hope this helps!!

And try using a UIScrollView

Upvotes: 1

thisisablock
thisisablock

Reputation: 559

You don't need to Use a UIImageview additionally.

For Local files use file:// as url. you can get a path of a file width:

NSString *path = [[NSBundle mainBundle] pathForResource:@"myimage" ofType:@"jpg"];

For the Webview simple create a Html Code as String.

[webView loadHTMLString: [NSString stringWithFormat:@"<html><head></head><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];

Inside the HTML String you can also use CSS for sizing or positioning!

Upvotes: 1

Related Questions