总结工作中一些常用的公共类
来源:互联网 发布:精子优化处理 好贵 编辑:程序博客网 时间:2024/06/07 01:18
在工作当中经常要写一些公共的类,所以在这里做一个小小的总结,下面是代码
PublicCell,主要用于定义背景颜色
点h
#import <UIKit/UIKit.h>@interface PublicCell : UITableViewCell@property (nonatomic ,strong)UIView *selectView;@end
点m
#import "PublicCell.h"@implementation PublicCell- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { //定义原来的背景颜色为空 self.selectionStyle = UITableViewCellSelectionStyleNone; //自定义想要的颜色,一开始将背景颜色设置为空 _selectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)]; _selectView.backgroundColor = RGBCOLOR(234, 215, 184); _selectView.alpha = 0.0; [self.contentView addSubview:_selectView]; } return self;}- (void)showBackGroundColor{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; _selectView.alpha = kAlpha; _selectView.alpha = 0.0; [UIView commitAnimations]; }//点击cell的时候触发方法- (void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; if (selected) { [self showBackGroundColor]; } }
PublicNavigationController,定义bar
点m
- (void)viewDidLoad{ [super viewDidLoad];//自定义bar背景 [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"topbar"] forBarMetrics:UIBarMetricsDefault];}
PublicTabBarController,自定义整个tabBar,代码较多
点h
#import <UIKit/UIKit.h>#import "PublicNavigationController.h"//代理,当点击bar的时候触发@protocol PublicTabBarControllerDelegate <NSObject>@optional-(void)didSelectTabBarWithIndex:(int)index;@end@interface PublicTabBarController : UITabBarController{@private UIImageView *_tabBarBG; }@property(nonatomic,strong)PublicNavigationController *moreNav;@property(nonatomic,unsafe_unretained)id<PublicTabBarControllerDelegate>Odelegate;//显示bar的方法- (void)showTabBar;//隐藏bar的方法- (void)hiddenTabBar;@end
点m
@interface PublicTabBarController ()@end@implementation PublicTabBarController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; [self performSelector:@selector(loadViewControllers)]; [self performSelector:@selector(loadCustomTabBarView)]; }//加载视图- (void)loadViewControllers{ OnLineViewController *onLineVC = [[OnLineViewController alloc]initWithNibName:@"OnLineViewController" bundle:nil]; self.Odelegate = onLineVC; PublicNavigationController *onLineNav = [[PublicNavigationController alloc]initWithRootViewController:onLineVC]; DownLoadViewController *downLoadVC = [[DownLoadViewController alloc]initWithNibName:@"DownLoadViewController" bundle:nil]; self.Odelegate = downLoadVC; PublicNavigationController *downLoadNav = [[PublicNavigationController alloc]initWithRootViewController:downLoadVC]; MoreViewController *moreVC = [[MoreViewController alloc]initWithNibName:@"MoreViewController" bundle:nil]; _moreNav = [[PublicNavigationController alloc]initWithRootViewController:moreVC]; NSArray *viewControllers = @[onLineNav, downLoadNav, _moreNav]; [self setViewControllers:viewControllers animated:YES]; }//创建自定义背景- (void)loadCustomTabBarView{ // 初始化自定义TabBar背景 if (iPhone5) { _tabBarBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 516, 320, 52)]; }else{ _tabBarBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 480-52, 320, 52)]; } _tabBarBG.userInteractionEnabled = YES; _tabBarBG.image = [UIImage imageNamed:@"deepbar"]; [self.view addSubview:_tabBarBG]; NSArray *selectArray = @[@"home press",@"download press",@"more press"]; NSArray *normalArray = @[@"home normal",@"download normal",@"more normal"]; // 初始化自定义TabBarItem -> UIButton float coordinateX = 0; for (int index = 0; index < 3; index++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(-1+coordinateX, 3 , 107, 49); [button setBackgroundImage:[UIImage imageNamed:[normalArray objectAtIndex:index]] forState:UIControlStateNormal]; [button setBackgroundImage:[UIImage imageNamed:[selectArray objectAtIndex:index]] forState:UIControlStateSelected]; [button addTarget:self action:@selector(changeViewController:) forControlEvents:UIControlEventTouchUpInside]; button.tag = index+100; [_tabBarBG addSubview:button]; coordinateX += 107; } UIButton *btn1 = (UIButton *)[self.view viewWithTag:100]; btn1.selected = YES;}- (void)changeViewController:(UIButton *)button{ UIButton *btn1 = (UIButton *)[self.view viewWithTag:100]; UIButton *btn2 = (UIButton *)[self.view viewWithTag:101]; UIButton *btn3 = (UIButton *)[self.view viewWithTag:102]; self.selectedIndex = button.tag-100; button.selected = YES; //判断选中状态 switch (button.tag-100) { case 0:{ btn1.selected = YES; btn2.selected = NO; btn3.selected = NO; if ([self.Odelegate respondsToSelector:@selector(didSelectTabBarWithIndex:)]) { [self.Odelegate didSelectTabBarWithIndex:button.tag]; } } break; case 1:{ btn1.selected = NO; btn2.selected = YES; btn3.selected = NO; if ([self.Odelegate respondsToSelector:@selector(didSelectTabBarWithIndex:)]) { [self.Odelegate didSelectTabBarWithIndex:button.tag]; } } break; case 2:{ btn1.selected = NO; btn2.selected = NO; btn3.selected = YES; } break; default: break; } }- (void)showTabBar{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.34]; if (iPhone5) { _tabBarBG.frame = CGRectMake(0, 516, 320, 52); }else{ _tabBarBG.frame = CGRectMake(0, 480-52, 320, 52); } [UIView commitAnimations];}- (void)hiddenTabBar{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35]; if (iPhone5) { _tabBarBG.frame = CGRectMake(-320, 516, 320, 52); }else{ _tabBarBG.frame = CGRectMake(-320, 480-52, 320, 52); } [UIView commitAnimations];}
- 总结工作中一些常用的公共类
- 工作中一些常用的linux命令
- Java和Android中一些常用的公共方法
- 工作中对测试的一些总结
- 工作中遇见的一些问题总结
- 工作中常用的Linux命令总结
- 工作中常用的正则表达式总结
- 工作中常用 Git 命令的总结
- idea工作中常用的快捷键总结
- css工作中常用的效果总结
- js中常用的一些事件总结
- linux中一些常用的命令总结
- pytorch中一些常用方法的总结
- 工作中常用的一些javascript的小技巧
- 一些公共的常用WebService收藏
- iOS 开发 一些常用的公共方法
- 一些自己工作中常用但容易混淆或忘记的HTML标签属性用法,在此做个小总结
- 工作中常用的一些javascript小技巧(二)
- linux下面用安装包iso 搭建yum本地源
- LOGIC IO(逻辑读次数)= db block gets + consistent gets
- Linux终端下的颜色设置
- ffmepg 指定RTSP网络连接模式UDP还是TCP
- UpdatePanel和jQuery不兼容
- 总结工作中一些常用的公共类
- C语言知识点学习之volatile关键字
- Linux/Unix中的命令提示符prompt
- 关于header("Cache-control: private")
- C++ 回调函数 机制
- centos 6.4下openvswitch安装
- IOS 页面属性传值、委托传值、单例传值
- C# 语言规范--1.2 类型
- JavaWeb开发Spring MVC