我在学习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");
}
------解决方案--------------------
路过,希望找到高手。
------解决方案--------------------