我在学习UI控件的使用
今天想实现在UIImageView 上面添加一个UIButton,点击button以后输出一段话
但是我加上去以后不能点击button。
不知道是哪里写错了
我是初学者,可能问题很菜。求大神指点下啊!
我把截图跟代码都贴出来啊。
#import "AppDelegate.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor yellowColor];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(80, 140, 160, 80)];
//imgView.highlighted = NO;
imgView.backgroundColor = [UIColor greenColor];
imgView.image = [UIImage imageNamed:@"BB"];
[self.window addSubview:imgView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(80, 40, 80, 40);
// btn.selected = YES;
[btn setTitle:@"点我" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(touchUpInside) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:btn];
// btn.enabled = YES;
[self.window makeKeyAndVisible];
return YES;
}-(void)touchUpInside
{
NSLog(@"touchUpInside");
}
今天想实现在UIImageView 上面添加一个UIButton,点击button以后输出一段话
但是我加上去以后不能点击button。
不知道是哪里写错了
我是初学者,可能问题很菜。求大神指点下啊!
我把截图跟代码都贴出来啊。
#import "AppDelegate.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor yellowColor];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(80, 140, 160, 80)];
//imgView.highlighted = NO;
imgView.backgroundColor = [UIColor greenColor];
imgView.image = [UIImage imageNamed:@"BB"];
[self.window addSubview:imgView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(80, 40, 80, 40);
// btn.selected = YES;
[btn setTitle:@"点我" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(touchUpInside) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:btn];
// btn.enabled = YES;
[self.window makeKeyAndVisible];
return YES;
}-(void)touchUpInside
{
NSLog(@"touchUpInside");
}
解决方案 »
- vmware虚拟机中装了雪豹10.6 MAC系统, XCode4安装不了, 各位有什么解决办法吗?
- 刚接触iphone
- 用 NSInvocationOperation创建线程 需加什么framework么
- 乔布斯辞职,苹果一个时代的落幕。
- 有没有好的opengl es demo的好的网站?
- 怎么删除iphone桌面图标
- Xcode 6 免证书真机调试
- iphone开发中数据存储 属性列表,归档,SQLite3,core data 还有FMDB应该选择哪种?
- MPMoviePlayerController 全屏横屏设置
- iOS FFMpeg 摄像头视频流如何进行h.264编码
- 请教个问题,http在iphone的 2G(GPRS)不能下载大文件
- iOS的视图切换问题
所以只要加上一句imgView.userInteractionEnabled = YES;