为啥在UIImageView上添加button以后点击button不能执行
1个回答
展开全部
我在学习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");
}
更多内容请看www.viiboo.cn
今天想实现在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");
}
更多内容请看www.viiboo.cn
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询