哈哈哈嘿嘿嘻嘻 2015-10-12 08:07 采纳率: 0%
浏览 2352

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这个方法啊 求解答

  • 写回答

5条回答 默认 最新

  • LUCKEYMAN 2015-10-12 08:58
    关注

    你的button是加在imageview上面,加在self上面试试看。

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题