开发者社区> 问答> 正文

关于ios UIView中的UIButton不能点击按钮 的问题

.h文件

import 

@interface HUPrompt : UIView

.m文件

import "HUPrompt.h"

import "UIView+Layout.h"

@implementation HUPrompt

UIImageView *backView = [[UIImageView alloc] init];

backView.frame = self.frame;
 backView.image = _backImage;
 [self addSubview:backView];
 self.button = [[UIButton alloc] initWithFrame:CGRectMake(0, label.bottom+23, 74, 32)];

self.button.isPercentSize = YES;
 self.button.backgroundColor = Btn_COLOR;
 [self.button setTitle:@"知道了" forState:UIControlStateNormal];
 [self.button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
 [self.button addTarget:self action:@selector(cancle1) forControlEvents:UIControlEventTouchUpInside];
 self.button.titleLabel.font = TextSize;
 self.button.layer.cornerRadius = 15;
 self.button.layer.masksToBounds = YES;
 [backView addSubview:self.button];
 self.button.isHorizontalCenter = YES;
 -(void)cancle1{

NSLog(@"sdfdsfds");
 }

然后我在uiviewController调用 能显示 frame是传进来了的 但是不能点击 没触发事件 我想是不是uiview中不能用addTarget这个方法啊

展开
收起
爵霸 2016-03-11 10:10:00 2513 0
1 条回答
写回答
取消 提交回答
  • HUPrompt : UIView 本身就是一个view,你用覆盖一个backView,完全是多余的,你发现了没

    2019-07-17 18:58:31
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载