TabBar中间拱起的两种思路:

一, UITabBarController 的 tabBar 上,添加 subView . 中间的按钮图片放大点。

methodOne.png

点击这里,没反应的。

TabBar 的 代码
- (void)itemSelected:(LLTabBarItem *)sender {
    if (sender.tabBarItemType != LLTabBarItemRise) {
        [self setSelectedIndex:sender.tag];
    } else {
        // 中间的
        if (self.delegateLLTabBar) {
            if ([self.delegateLLTabBar respondsToSelector:@selector(tabBarDidSelectedRiseButton)]) {
                [self.delegateLLTabBar tabBarDidSelectedRiseButton];
            }
        }
    }
}
- (void)setTabBarItemAttributes:(NSArray<NSDictionary *> *)tabBarItemAttributes {

......

    for (id item in _tabBarItemAttributes) {
        if ([item isKindOfClass:[NSDictionary class]]) {

......
            
            if (tabBarItem.tabBarItemType != LLTabBarItemRise) {
                tabBarItem.tag = itemTag;
                itemTag++;
            } else {
                passedRiseItem = YES;
            }

......

        }
    }
}
TabBar 上面的 Button 的 代码
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.titleLabel sizeToFit];
    CGSize titleSize = self.titleLabel.frame.size;

    CGSize imageSize = [self imageForState: UIControlStateNormal].size;
    if (imageSize.width != 0 && imageSize.height != 0) {
        CGFloat imageViewCenterY = CGRectGetHeight(self.frame) - 3 - titleSize.height - imageSize.height / 2 - 5;
        self.imageView.center = CGPointMake(CGRectGetWidth(self.frame) / 2, imageViewCenterY);
    } else {
        CGPoint imageViewCenter = self.imageView.center;
        imageViewCenter.x = CGRectGetWidth(self.frame) / 2;
        imageViewCenter.y = (CGRectGetHeight(self.frame) - titleSize.height) / 2;
        self.imageView.center = imageViewCenter;
    }
这个方法比较少用。

imageForState:
Returns the image used for a button state.

二, TabBarViewController 中, 设置 tabBar 的 图片 偏移

methodTwo.png
作用域增加,点击上方, 起到 点击下方 效果。
 override func viewWillLayoutSubviews() {
        //重新设置tabbar 的高度
        var frame = self.tabBar.frame
        frame.size.height = myHeight
        frame.origin.y = self.view.frame.size.height - myHeight
        self.tabBar.frame = frame
        self.tabBar.barStyle = .default
        //设置图片偏移,因为加高了tabbar
        for i in 0..<self.tabBar.items!.count {
            let item = self.tabBar.items![i]
            if i != 2 {
                item.imageInsets = UIEdgeInsets(top: myHeight - 49 - 5, left: 0, bottom: -(myHeight - 49 - 5), right: 0)
            }
            else{
                item.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
            }
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,190评论 4 61
  • 想着该干什么了,心绪却越想越烦乱,莫名其妙的烦乱了起来。说不出是何种原因。 都好久讨厌打问号了,太容易带给人疑惑。...
    林子源阅读 2,920评论 5 13
  • 第一次觉得自己的名字很有价值的时候,是爸爸去世之后在遗产公证声明上的那一个又一个亲笔签名,走出公证处时,看着...
    桃之夭夭未命名阅读 4,143评论 0 0
  • 北京新世纪医学模式研究院的宗旨与指导原则 经过十多年的长期酝酿,中国第一个、世界第一个,北京新世纪医学模式研究院终...
    新世纪医学模式研究院阅读 3,134评论 0 1
  • 旅游的过程, 往往没有想象的那么美好, 让人不堪回首的太多。 高速的拥堵, 订酒店的艰难, 景区人满为患。 可为什...
    火禾一阅读 2,394评论 0 0