在Label上加Button 我在label 上加了一个 button 想看看userInteractionEnabled的效果 为什么button在label的下面? 求大神简单讲一下用户交互的使用,以及在项目中的情况! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、userInteractionEnabled属性决定UIView是否接受并响应用户的交互,为啥要将UIButton添加到UILable上看效果2、关于Button在Label的下面,你可以试试 bringSubviewToFront添加视图控件,而不是subView 不好使啊 button 还是在label 下面 UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; [label setBackgroundColor:[UIColor redColor]]; [self.view addSubview:label]; UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(20,20, 64, 64)]; [button setBackgroundColor:[UIColor greenColor]]; [label addSubview:button]; [label bringSubviewToFront:button]; CGRectMake(0, 0, 100, 100)] CGRectMake(0,0, 64, 64) 其实btn已经在lable的上面了。而且 [label bringSubviewToFront:button]; 是去掉。。只是你设置的坐标显示的问题 只要设置了label.text的属性就可以了,设置成空也成,但是一定要设置 我遇到和楼主一样的问题,设置label.text也不行,哪位大牛来解答下? UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 450, 350, 40)]; label.textAlignment=2; [self.view addSubview:label]; UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem]; btn.frame=CGRectMake(0, 0, 40, 28); [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];// [btn setBackgroundColor:[UIColor grayColor]]; [btn setTitle:@"点点" forState:UIControlStateNormal]; [label addSubview:btn];// [label bringSubviewToFront:btn]; label.userInteractionEnabled=YES; button的父视图需要设置user interaction属性为yes // self.textBackLabel.clipsToBounds = YES; //显示子视图// self.textBackLabel.text = @"中文"; //设置文字可以显示子视图 必须在后面 中文不显示 数字英文可以显示// self.textBackLabel.backgroundColor = [UIColor grayColor]; //设置了颜色不显示子视图// [self.textBackLabel layoutIfNeeded ]; //显示子视图百度 code_小马 ,我的简书里边有详细解释 xcode黑屏 哪里能下载到iphone sdk 3.1.3?找了好多地方都没找到。 哎.. 困扰我几天了 有高手请进 谢谢 怎样使用Core Location使用地图? 如何将程序上传到appstore上? mac库文件系统目录 iOS阅读器问题怎么解决字符编码问题 请问下java下得writeUTF 和readUTF方法,在ios里面对应的是什么方法? 现在mobile开发的趋势是怎么样的? 请教关于iOS集成微信支付的一些问题 使用AudioQueue播放声音出错 IOS加载HTML5数据问题
2、关于Button在Label的下面,你可以试试 bringSubviewToFront添加视图控件,而不是subView
[label setBackgroundColor:[UIColor redColor]];
[self.view addSubview:label];
UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(20,20, 64, 64)];
[button setBackgroundColor:[UIColor greenColor]];
[label addSubview:button];
[label bringSubviewToFront:button];
label.textAlignment=2;
[self.view addSubview:label];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem];
btn.frame=CGRectMake(0, 0, 40, 28);
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
// [btn setBackgroundColor:[UIColor grayColor]];
[btn setTitle:@"点点" forState:UIControlStateNormal];
[label addSubview:btn];
// [label bringSubviewToFront:btn];
label.userInteractionEnabled=YES;
// self.textBackLabel.text = @"中文"; //设置文字可以显示子视图 必须在后面 中文不显示 数字英文可以显示
// self.textBackLabel.backgroundColor = [UIColor grayColor]; //设置了颜色不显示子视图
// [self.textBackLabel layoutIfNeeded ]; //显示子视图
百度 code_小马 ,我的简书里边有详细解释