2012-02-08 99 views
0

我希望能夠將縮放功能添加到UIImage,並且相信最好的方法是嵌入到UIWebview中。有人能夠幫助我實現這一目標嗎?以編程方式將UIWebView添加到UIImageView

- (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]; 


} 
+0

我想用一個UIScrollView會是一個更好的辦法 - 看到這個[問題](http://stackoverflow.com/questions/2685161/iphone-uiscrollview-and-uiimageview-setting -initial-zoom) – Jason 2012-02-08 01:29:35

+0

如何使用滾動視圖縮放並應用到上面的代碼? – CraigBellamy 2012-02-08 09:08:29

+0

試試我的代碼,它適合我! :d – iProRage 2012-02-09 02:07:54

回答

1

嘗試添加以下內容到viewDidLoad方法,

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

希望這有助於!

並嘗試使用一個UIScrollView

1

您不需要額外使用UIImageview。

對於本地文件使用file:// as url。你可以得到一個文件寬度的路徑:

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

對於Webview的簡單創建一個HTML代碼作爲字符串。

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

在HTML字符串中,您還可以使用CSS進行大小調整或定位!

相關問題