自定义标题栏
来源:互联网 发布:哪个打字软件最好用 编辑:程序博客网 时间:2024/06/06 03:52
主要类
FootBar.h
#import <UIKit/UIKit.h>#import "FootBarItem.h"@interface FootBar : UIScrollView-(void) setDataScoure:(NSArray *)footBarItems withTitleNortalColor:(UIColor *)nortalColor withTitleSelectColor:(UIColor *)selectColor;-(void) selectPosition:(int) position;@end
FootBar.m
//// FootBar.m// TyApp//// Created by TY-DENG on 17/5/16.// Copyright © 2017年 Lin. All rights reserved.//#import "FootBar.h"#import "FootBarItem.h"@implementation FootBar{ NSArray *dataScoure; UIColor *titleSelectColor; UIColor *titleNortalColor; int oldSelectPosition;}-(void) setDataScoure:(NSArray *)footBarItems withTitleNortalColor:(UIColor *)nortalColor withTitleSelectColor:(UIColor *)selectColor{ dataScoure = footBarItems; titleSelectColor = selectColor; titleNortalColor = nortalColor; oldSelectPosition = -1; [self setView];}-(void) setView{ int wid = self.frame.size.width/dataScoure.count; for (int i =0; i<dataScoure.count; i++) { FootBarItem *item = dataScoure[i]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(wid*i, 0, wid, self.frame.size.height)]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((wid-18)/2, 4, 20, 20)]; [button setTag:1000+i]; [imageView setImage:[UIImage imageNamed:item.imageNortalName]]; [imageView setTag:2000+i]; [button addSubview:imageView]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 24, wid, 20)]; [title setText:item.title]; [title setFont:[UIFont systemFontOfSize:13]]; [title setTextColor:titleNortalColor]; [title setTextAlignment:NSTextAlignmentCenter]; [title setTag:3000+i]; [button addTarget:self action:@selector(butonAction:) forControlEvents:UIControlEventTouchUpInside]; [button addSubview:title]; [self addSubview:button]; }}-(void) selectPosition:(int) position{ if (oldSelectPosition >= 0) { //设置原来被选择的状态 FootBarItem *item0 = dataScoure[oldSelectPosition]; UIButton *button0 = [self viewWithTag:1000+oldSelectPosition]; UIImageView *iamgeView0 = [button0 viewWithTag:2000+oldSelectPosition]; if (iamgeView0) { [iamgeView0 setImage:[UIImage imageNamed:item0.imageNortalName]]; } UILabel *title0 = [button0 viewWithTag:3000+oldSelectPosition]; if (title0) { [title0 setTextColor:titleNortalColor]; } } //设置新选择的状态 FootBarItem *item = dataScoure[position]; UIButton *button = [self viewWithTag:1000+position]; UIImageView *iamgeView = [button viewWithTag:2000+position]; if (iamgeView) { [iamgeView setImage:[UIImage imageNamed:item.imageSelectName]]; } UILabel *title = [button viewWithTag:3000+position]; if (title) { [title setTextColor:titleSelectColor]; } oldSelectPosition = position; //在这里可以创建代理,实现回调,当然使用Block也是可以的。}-(void) butonAction:(UIButton *) sender{ [self selectPosition:((int)sender.tag - 1000)];}@end
适配工具类
FootBarItem.h
#import <Foundation/Foundation.h>@interface FootBarItem : NSObject@property (strong,nonatomic) NSString *title;@property (strong,nonatomic) NSString *imageSelectName;@property (strong,nonatomic) NSString *imageNortalName;-(id) initWithTitile:(NSString *) title withNortalImageName:(NSString *) nortalImageName withSelectImageName:(NSString *)selectImageName;@end
FootBarItem.m
//// FootBarItem.m// TyApp//// Created by TY-DENG on 17/5/16.// Copyright © 2017年 Lin. All rights reserved.//#import "FootBarItem.h"@implementation FootBarItem-(id) initWithTitile:(NSString *) title withNortalImageName:(NSString *) nortalImageName withSelectImageName:(NSString *)selectImageName{ self = [super init]; self.title = title; self.imageNortalName = nortalImageName; self.imageSelectName = selectImageName; return self;}@end
阅读全文
0 0
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义 标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- Fast特征检测
- 最右校招-服务器日志分析:一个十万行log统计问题的c语言代码的实现2
- Vampire Numbers 数字的合理分解
- Android开发者-对Java和编程的一点总结
- SpringMVC详解
- 自定义标题栏
- pat 1059. Prime Factors
- UESTC 1603 BanG Dreamer 小根堆、贪心+set<pair<int, int>>+low_bound
- WCF、WebAPI、WCFREST、WebService之间的区别
- 5(2)、uboot源码——uboot的环境变量
- 使用 HTMLTestRunner.py 修改为Python3版本
- Java Web jsp连接数据库并将数据库数据显示在浏览器页面
- CreateEvent的用法
- 实现mysql远程访问