自定义tablebar
来源:互联网 发布:暮色谷的新域名问题 编辑:程序博客网 时间:2024/06/03 21:01
// TablebarView.h
#import <UIKit/UIKit.h>
#pragma mark - 延展
@protocol TablebarViewDelegate <NSObject>
- (void)tablebarViewDelegate:(NSInteger )tag;
@end
@interface TablebarView : UIView
@property (nonatomic,strong) id<TablebarViewDelegate>delegate;
@property (nonatomic,strong) UIButton *button1;
@property (nonatomic,strong) UIButton *button2;
@property (nonatomic,strong) UIButton *button3;
@property (nonatomic,strong) UIButton *button4;
@property (nonatomic,strong) UIButton *button5;
@end
// TablebarView.m
#import "TablebarView.h"
#define W [UIScreen mainScreen].bounds.size.width
@implementation TablebarView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor colorWithRed:233/255.f green:156/255.f blue:175/255.f alpha:1];
self.button1 = [UIButton buttonWithType:UIButtonTypeCustom];
self.button1.frame = CGRectMake(10,0, W / 5 - 5 , 44);
[self.button1 setImage:[UIImage imageNamed:@"home"] forState:UIControlStateNormal];
self.button1.tag = 1;
[self.button1 addTarget:self action:@selector(tableBarDelegate:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.button1];
self.button2 = [UIButton buttonWithType:UIButtonTypeCustom];
self.button2.frame = CGRectMake(W / 5 + 5 , 0, W /5 - 5, 44);
[self.button2 setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
self.button2.tag = 2;
[self.button2 addTarget:self action:@selector(tableBarDelegate:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.button2];
self.button3 = [UIButton buttonWithType:UIButtonTypeCustom];
self.button3.frame = CGRectMake(W / 2 - W / 5 / 2 , 0, W / 5 , 44);
[self.button3 setImage:[UIImage imageNamed:@"相机"] forState:UIControlStateNormal];
self.button3.tag = 3;
[self.button3 addTarget:self action:@selector(tableBarDelegate:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.button3];
self.button4 = [UIButton buttonWithType:UIButtonTypeCustom];
self.button4.frame = CGRectMake(W / 2 - W / 5 / 2 + W / 5, 0, W / 5 - 5, 44);
[self.button4 setImage:[UIImage imageNamed:@"心"] forState:UIControlStateNormal];
self.button4.tag = 4;
[self.button4 addTarget:self action:@selector(tableBarDelegate:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.button4];
self.button5 = [UIButton buttonWithType:UIButtonTypeCustom];
self.button5.frame = CGRectMake(W - W /5 - 10, 0, W / 5 - 5, 44);
[self.button5 setImage:[UIImage imageNamed:@"人"] forState:UIControlStateNormal];
self.button5.tag = 5;
[self.button5 addTarget:self action:@selector(tableBarDelegate:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.button5];
}
return self;
}
- (void)tableBarDelegate:(UIButton *)buttonTag {
[self.delegate tablebarViewDelegate:buttonTag.tag];
}
@end
// ViewController.m
TablebarView *tableBar = [[TablebarViewalloc]init];
tableBar.frame= CGRectMake(0,HEIGHT - 44,self.view.frame.size.width,44);
tableBar.button1.backgroundColor= [UIColorcolorWithRed:244/255.fgreen:209/255.fblue:228/255.falpha:0.7];
tableBar.button2.backgroundColor= [UIColorclearColor];
tableBar.button3.backgroundColor= [UIColorcolorWithRed:218/255.fgreen:59/255.fblue:99/255.falpha:1];
tableBar.button4.backgroundColor= [UIColorclearColor];
tableBar.button5.backgroundColor= [UIColorclearColor];
tableBar.delegate= self;
[self.viewaddSubview:tableBar];
- (void)tablebarViewDelegate:(NSInteger)tag {
if (tag ==2) {
SearchViewController *sousuo = [[SearchViewControlleralloc]init];
[self.navigationControllerpushViewController:sousuoanimated:YES];
}
if (tag ==3) {
PhoneViewController *phone = [[PhoneViewControlleralloc]init];
[self.navigationControllerpushViewController:phoneanimated:YES];
}
if (tag ==4) {
LikeViewController *like = [[LikeViewControlleralloc]init];
[self.navigationControllerpushViewController:likeanimated:YES];
}
if (tag ==5) {
MyViewController *my = [[MyViewControlleralloc]init];
[self.navigationControllerpushViewController:myanimated:YES];
}
#import "SearchViewController.h"
#import "TablebarView.h"
#import "MyViewController.h"
#import "LikeViewController.h"
#import "PhoneViewController.h"
#import "ViewController.h"
@interface SearchViewController ()<TablebarViewDelegate>
@end
@implementation SearchViewController
- (void)setNavigationBar {
self.navigationItem.title =@"POCKET IDOL";
[self.navigationController.navigationBarsetBarTintColor:[UIColorcolorWithRed:244/255.0fgreen:162/255.0fblue:184/255.0falpha:1]];
/* 标题颜色的更改 */
NSDictionary *dictionary = [NSDictionarydictionaryWithObjectsAndKeys:[UIFontfontWithName:@"A_LANCETRGH"size:0.0],NSFontAttributeName, [UIColorwhiteColor], NSForegroundColorAttributeName,nil];
self.navigationController.navigationBar.titleTextAttributes = dictionary;
}
- (void)viewWillAppear:(BOOL)animated {
//隐藏导航栏
self.navigationController.navigationBarHidden =NO;
// self.navigationController.tabBarItem = NO;
}
- (void)bar {
TablebarView *tableBar = [[TablebarViewalloc] init];
tableBar.frame = CGRectMake(0, HEIGHT - 44, self.view.frame.size.width,44);
tableBar.button1.backgroundColor = [UIColorclearColor];
tableBar.button2.backgroundColor = [UIColorcolorWithRed:244/255.fgreen:209/255.fblue:228/255.falpha:0.7];
tableBar.button3.backgroundColor = [UIColorcolorWithRed:218/255.fgreen:59/255.fblue:99/255.falpha:1];
tableBar.button4.backgroundColor = [UIColorclearColor];
tableBar.button5.backgroundColor = [UIColorclearColor];
tableBar.delegate = self;
[self.viewaddSubview:tableBar];
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColorwhiteColor];
[selfsetNavigationBar];
[self bar];
}
- (void)tablebarViewDelegate:(NSInteger)tag {
if (tag == 3) {
PhoneViewController *phone = [[PhoneViewControlleralloc] init];
[self.navigationControllerpushViewController:phone animated:YES];
}
if (tag == 4) {
LikeViewController *like = [[LikeViewControlleralloc] init];
[self.navigationControllerpushViewController:like animated:YES];
}
if (tag == 5) {
MyViewController *my = [[MyViewControlleralloc] init];
[self.navigationControllerpushViewController:my animated:YES];
}
if (tag == 1) {
[self.navigationControllerpopToRootViewControllerAnimated:YES];//返回第一页
}
if (tag == 2) {
SearchViewController *sear = [[SearchViewControlleralloc] init];
[self.navigationControllerpushViewController:sear animated:YES];
}
}
- 自定义tablebar
- iOS 之自定义TableBar
- ios weibo 搭建 自定义tableBar
- 封装的tableBar
- tableBar 添加多个按钮的方法
- 从一个无tableBar页面popToRootViewController
- tableBar 嵌套NavGationController 无法使用手势返回的问题
- swift4 push 跳转页面时 隐藏下面的TableBar
- TabBar的使用,一个应用程序中,tablebar始终存在于界面下方
- 从一个页面跳转到tableBar相应的selectIndex时相应的方法
- 自定义
- 自定义
- 自定义
- 自定义
- 自定义
- 自定义TexBox,自定义ComboBox
- 自定义View自定义属性
- 自定义View自定义属性
- //UITextField控制只输入数字
- 瀑布流特效,回到顶部特效,放大镜特效,选项卡原理分析
- Java 使用 SlfLog4J 写日志
- Python基础(一)Hello World!
- java 继承、抽象、private、static、final关键字在类中的使用
- 自定义tablebar
- 广播实现的方式
- 关于 angularjs 的小结
- lua tutorial 05
- 【观察者模式】的故事来源(Observer Pattern)
- 三大WEB服务器对比分析
- 在struts中犯的错误
- 面试中的常见问题
- UIWebView加载本地文件