改变继承UIButton的两个子类状态
来源:互联网 发布:手机虚拟摇杆软件 编辑:程序博客网 时间:2024/05/18 02:27
各位我在做四个按钮,刚刚开始的时候第一个按钮为选中状态,然后接下来点击哪个哪个按钮上的图片和字体颜色改变。可是我用下面的for循环出来了四个button可是它显示出来的状态都是位最后一个按钮为选中状态。这个是怎么回事呢?
-(void)loadCustomTabBarView{
//初始化自定义TabBar背景
UIImageView *imageBG = [[UIImageView alloc]initWithFrame:CGRectMake(0, SCREEN_H-50, SCREEN_W, 49)];
imageBG.backgroundColor = [UIColor lightGrayColor];
imageBG.userInteractionEnabled = YES;
[self.view addSubview:imageBG];
//初始化自定义TabBar
float coordinateX = 0;
for (int i=0; i<4; i++) {
button = [[UIButton alloc]init];
button.frame = CGRectMake(20+coordinateX, 0, 49, 49);
button.tag = i;
[button addTarget:self action:@selector(changeViewController:) forControlEvents:UIControlEventTouchUpInside];
[imageBG addSubview:button];
coordinateX +=75;
//初始化自定义选中背景
selectedView = [[UIImageView alloc]init];
selectedView.frame = CGRectMake(7,4,27,27);
selectedView.tag = i;
selectedView.image = [UIImage imageNamed:[imageNameArray objectAtIndex:i]];
[button addSubview:selectedView];
label = [[UILabel alloc]init];
label.frame = CGRectMake(0, 33, 49, 14);
label.text = [tabName objectAtIndex:i];
label.tag = i;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:12.0f];
[button addSubview:label];
}
}
-(void)changeViewController:(UIButton *)sender{
self.selectedIndex = sender.tag;
label.textColor = RGB(251, 44, 10, 1);
selectedView.image = [UIImage imageNamed:[imageSelectArray objectAtIndex:sender.tag]];
}
0 0
- 改变继承UIButton的两个子类状态
- 改变继承UIButton的两个子类状态
- 去掉UIButton状态改变时的动画
- iOS UIButton实现点击后两种状态的相互改变效果
- 子类能继承父类的所有方法和状态
- UIButton的状态
- UIButton的selected状态
- UIButton的点击状态
- UIButton的状态
- [Unity&C#&继承]unity怎么改变继承子类的父类的函数
- 在程序运行期间,点击UIbutton,如何生成和改变uiview及其子类的内容title等
- 子类的继承
- 子类的继承性
- UIButton改变字的颜色
- C++ public继承后,子类能改变父类的成员变量吗?
- C++子类继承父类后子类的大小
- java中,子类能不能继承父类的所有方法和状态?
- 当两个类构成继承关系时,子类是否必须重写父类的所有方法?
- 【寒江雪】Direct3D11中的可编程光照
- 表单的内容如何存入数据库中
- 求教Android蓝牙串口开发OutputStream发送数据失败的问题。
- iOS用 afnetworking post给服务器,php获取到的中文是乱码
- 为什么我的网站谷歌和360浏览器打开乱码啊
- 改变继承UIButton的两个子类状态
- Leetcode-205. Isomorphic Strings
- Android版本的问题
- Delphi XE5 开发android环境配置
- 200分 android-vlc播放视频
- 如何在不同的手机上获得软键盘的高度
- GridView刷新问题
- nsxmlparser解析xml出错
- Leetcode-206. Reverse Linked List