2010-04-08 84 views
0

CGRect frame = CGRectMake(round((self.view.bounds.size.width-kImageWidth)/ 2.0), kTopPlacement,kImageWidth,kImageHeight); self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease]; [self.view addSubview:self.containerView];在圖像中添加按鈕

// create the initial image view 
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight); 
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease]; 
self.mainView.image = [UIImage imageNamed:imagePath]; 

我想在mainview.image中放一個按鈕。我該怎麼做?

任何幫助將不勝感激。

回答

0

你必須創建一個按鈕。

,並使用代碼添加MAINVIEW作爲一個子視圖到該按鈕:

[btnButton addSubView:mainView]; 

,並作爲一個子視圖添加此按鈕將ViewContoller的觀點

[self.view addSubView:btnButton]; 
+0

它現在的工作!非常感謝!! – isarathg 2010-04-09 17:55:27

0

可能更容易使用UIButton並添加圖像作爲背景。

只看配置按鈕使用圖像

你也可以在UIImageView的頂部添加一個清除按鈕(使用UIButtonTypeCustom)如果你想按鈕只佔用部分圖像的部分。