UITabBarController相关知识

UITabBarItem的相关属性

<pre>
// 通过appearance统一设置所有UITabBarItem的文字属性
// 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
UITabBarItem *item=[UITabBarItem appearance];
//设置tabaritem的正常情况下的属性
NSMutableDictionary *textArr=[NSMutableDictionary dictionary];
textArr[NSForegroundColorAttributeName]=[UIColor redColor];//文字颜色
[item setTitleTextAttributes:textArr forState:UIControlStateNormal];
</pre>

设置UITabBarItem的图片和文字title

<pre>
//设置文字
childVc.tabBarItem.title=title;
// 设置子控制器的图片
childVc.tabBarItem.image = [UIImage imageNamed:image];
// //使用指定渲染模式---总是绘制原始图像,而不将它视为模板(搞掉系统默认)
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
</pre>

UITabBarController代理
1.是否允许选择不同item触发后续操作,YES 允许,NO不允许

<pre>

  • (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
    NSLog(@"hello");
    return YES;
    }
    </pre>
2.每次点击tabBarItem后触发这个方法(只有点击标签栏中的五个按钮才会触发,MORE里边的不会触发)

<pre>

  • (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {

    NSLog(@"%@!",viewController.title);
    }
    </pre>

3.当点击moreNaviegationController中的编辑按钮时触发的方法

<pre>

  • (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
    {
    NSLog(@"biaji");
    }
    </pre>
4.当点击完成按钮的时候,触发此方法

<pre>
//changed : 标记viewController的顺序是否改变
//ViewControllers 返回最新的tabBarController中viewControllers

  • (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed NS_AVAILABLE_IOS(3_0)
    {
    if(changed)
    {
    NSLog(@"change@");
    }
    else
    {
    NSLog(@"not change");
    }

    for(UIViewController *vc in viewControllers)
    {
    NSLog(@"%@",vc.title);
    }
    }
    </pre>

常用的事件UIControlState

UIControlStateNormal 正常状态
UIControlStateHighlighted 高亮状态
UIControlStateDisabled 不可点击状态
UIControlStateSelected 选中状态

常见的属性及说明(富文本属性)

NSFontAttributeName 字体

NSParagraphStyleAttributeName 段落格式

NSForegroundColorAttributeName 字体颜色

NSBackgroundColorAttributeName 背景颜色

NSStrikethroughStyleAttributeName 删除线格式

NSUnderlineStyleAttributeName 下划线格式

NSStrokeColorAttributeName 删除线颜色

NSStrokeWidthAttributeName 删除线宽度

NSShadowAttributeName 阴影

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容