在图像中添加按钮
问题描述:
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中放一个按钮。我该怎么做?
任何帮助将不胜感激。
答
你必须创建一个按钮。
,并使用代码添加MAINVIEW作为一个子视图到该按钮:
[btnButton addSubView:mainView];
,并作为一个子视图添加此按钮将ViewContoller的观点
[self.view addSubView:btnButton];
答
可能更容易使用UIButton并添加图像作为背景。
只看配置按钮使用图像
你也可以在UIImageView的顶部添加一个清除按钮(使用UIButtonTypeCustom)如果你想按钮只占用部分图像的部分。
它现在的工作!非常感谢!! – isarathg 2010-04-09 17:55:27