专栏首页iOS知识点iOS TabBarController实例
原创

iOS TabBarController实例

-(BaseNavigationController*)setTabBarItemWithRootVC:(id)vc Image:(NSString*)imgName SelectedImage:(NSString*)selectedImg
{
    BaseNavigationController *nav = [[BaseNavigationController alloc] init];
    [nav.tabBarItem setImage:[[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [nav.tabBarItem setSelectedImage:[[UIImage imageNamed:selectedImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [nav.tabBarItem setImage:[[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [nav.tabBarItem setSelectedImage:[[UIImage imageNamed:selectedImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    returnnav;
}

1.设置按钮操作

//返回按钮    
UIBarButtonItem * buttonItem = [[UIBarButtonItem alloc]initWithTitle:nil style:UIBarButtonItemStyleDone target:self action:@selector(backIndex)];
    [buttonItem setImage:[UIImage imageNamed:@"返回"]];
    self.navigationItem.leftBarButtonItem= buttonItem;

//导航栏标题
    self.navigationItem.title = @"个人中心";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[XUtil hexToRGB:@"333333"],NSFontAttributeName:[UIFont systemFontOfSize:16]}];


    //左键
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backIndex) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];

    self.navigationItem.leftBarButtonItem = leftItem;
    //导航栏标题
    self.navigationItem.title = @"单词详解";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[XUtil hexToRGB:@"2E2F33"],NSFontAttributeName:[UIFont systemFontOfSize:16]}];

    //右键
    UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [moreBtn setTitle:@"更多" forState:UIControlStateNormal];
    [moreBtn setTitleColor:UIColorFromRGB(0xBDBEBF) forState:UIControlStateNormal];
    moreBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [moreBtn addTarget:self action:@selector(quci) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:moreBtn];
    self.navigationItem.rightBarButtonItem = rightItem;

//把view添加到nav
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:barView];

2.如何找到searchBar中的UItextField并修改

    searchView.frame = CGRectMake(0, kStatusBarHeight + Main_Screen_Width * 10 / 640, Main_Screen_Width * 470 / 640, kTopBarHeight);
    
    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 284 * adjustWidth, kTopBarHeight)];
    //    ViewRadius(searchBar,8.0);
    searchBar.delegate = self;
    searchBar.barTintColor = [UIColor clearColor];
    UITextField* searchTextField = [[[searchBar.subviews firstObject] subviews] lastObject];
    searchTextField.dk_textColorPicker = DKColor_TEXTCOLOR_TITLE;
    searchTextField.font = font14;
    searchBar.searchBarStyle = UISearchBarStyleMinimal;
    searchBar.barStyle = UIBarStyleDefault;
    [searchBar.layer setBorderWidth:1.0];
    searchBar.layer.borderColor = [[UIColor clearColor] CGColor];
    searchBar.backgroundColor=[UIColor clearColor];
    searchBar.placeholder = @"请输入关键字名称";
    [searchView addSubview:searchBar];
    [searchBar becomeFirstResponder];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchView];

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • iOS 点击按钮复制文本

    Lee坚武
  • iOS 实时监听UITextField输入事件

    Lee坚武
  • iOS tableViewCell最右边显示箭头,字符,自定义分割线

    ![image.png](https://upload-images.jianshu.io/upload_images/659494-f8437106309f1...

    Lee坚武
  • LaTeX:斜线表头的表格制作

    需求:正规表格的左上角"第一个单元是表头",一般都是用"斜线分区"的!本文介绍其实现方法:不仅适用在表头,表中任何一个单元位置都适用。

    于小勇
  • 小程序wx:if与hidden比较

    薛定喵君
  • 大分区表的手工并行优化

    这段时间饱受大分区表的性能之苦,碰到最大的一个分区表有1个t左右,操作起来每个细节都需要格外小心,我这次和大家分享的案例应用的分区表不是很大,有80G左右。但是...

    jeanron100
  • CentOs7.3 搭建 RabbitMQ 3.6 Cluster 集群服务

    CentOs7.3 搭建 RabbitMQ 3.6 Cluster 集群服务 RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种...

    搜云库
  • 解决thymeleaf模板严格要求格式

    微醺
  • 1017 A除以B (20 分)

    本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数。你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立。

    可爱见见
  • Spring Cloud Feign 启动UnsatisfiedDependencyException

    在加入Swagger之后启动就报错了,由此可知肯定是冲突了 错误信息如下: org.springframework.beans.factory.Unsatisf...

    猿天地

扫码关注云+社区

领取腾讯云代金券