ios 自定义tabbar

时间:2014-09-20 14:21:29   收藏:0   阅读:292

.h文件:

#import <UIKit/UIKit.h>

@interface YLYTabBar : UIView

@end

.m文件

#import "YLYTabBar.h"

@implementation YLYTabBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 1.设置背景色
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithNamed:@"tabbar_background"]];
        
    }
    return self;
}

使用:

-(void)addTabBar
{
    YLYTabBar *myTabBar = [[YLYTabBar alloc] init];
    myTabBar.frame = self.tabBar.bounds;
    [self.tabBar addSubview:myTabBar];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //移除之前的4各UITabBarButton
    for (UIView *child in self.tabBar.subviews) {
        if ([child isKindOfClass:[UIControl class]]) {
            [child removeFromSuperview];
        }
    }
}

 

原文:http://www.cnblogs.com/yuanliyong520/p/3983214.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!