作业

新建niuTableViewCell  继承UITableViewCell

新建zhexian  继承uiview

新建tabbarViewController    继承UITabBarController

新建oneViewController   继承UIViewController

新建twoViewController      threeViewController    fourViewController    fiveViewController  


在AppDelegate.M 中

导入#import "tabbarViewController.h"

 self.window.rootViewController = [tabbarViewController new];

在niuTableViewCell.h中

@property(nonatomic,strong)UIImageView *imageV;

@property(nonatomic,strong)UILabel *textL;

@property(nonatomic,strong)UILabel *detaL;

@property(nonatomic,strong)UILabel *dateL;



niuTableViewCell.m中

-(UIImageView *)imageV

{

    if(!_imageV) {

        _imageV= [[UIImageViewalloc]init];

        _imageV.frame=CGRectMake(FIT_X(20),FIT_X(5),FIT_X(90),FIT_X(70));

    }

    return _imageV;

}

-(UILabel*)textL

{

    if(!_textL) {

        _textL= [[UILabelalloc]init];

        _textL.frame=CGRectMake(self.imageV.frame.origin.x+self.imageV.frame.size.width+FIT_X(10),FIT_X(20),SCR_W-FIT_X(140),FIT_X(40));

        _textL.font= [UIFontsystemFontOfSize:14];

        _textL.numberOfLines = 0;

    }

    return _textL;

}

-(UILabel*)detaL

{

    if(!_detaL) {

        _detaL= [[UILabelalloc]init];

        _detaL.frame = CGRectMake(self.imageV.frame.origin.x + self.imageV.frame.size.width + FIT_X(10),self.textL.frame.origin.y + self.textL.frame.size.height, FIT_X(80), FIT_X(12));

//        _detaL.frame = CGRectMake(10,10,10,10);


        _detaL.font= [UIFontsystemFontOfSize:12];

        _detaL.textColor = [UIColor yellowColor];

    }

    return _detaL;

}

-(UILabel*)dateL

{

    if(!_dateL) {

        _dateL= [[UILabelalloc]init];

        _dateL.frame=CGRectMake(self.detaL.frame.origin.x+self.detaL.frame.size.width+FIT_X(10),FIT_X(60),FIT_X(50),FIT_X(10));

        _dateL.font= [UIFontsystemFontOfSize:12];

//        _dateL.frame = CGRectMake(10, 10, 10, 10);



    }

    return _dateL;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier

{

    self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];

    if(self) {

        [selfaddSubview:self.imageV];

        [selfaddSubview:self.textL];

        [selfaddSubview:self.detaL];

        [selfaddSubview:self.dateL];

    }

    return self;

}

- (void)awakeFromNib {

    [super awakeFromNib];

    // Initialization code

}

在tabbarViewController.m中

导入#import "oneViewController.h"

#import "twoViewController.h"

#import "threeViewController.h"

#import "fourViewController.h"

#import "fiveViewController.h"

并且

- (void)viewDidLoad {

    [super viewDidLoad];

    oneViewController *one = [oneViewController new];

    UINavigationController *oneNav = [[UINavigationController alloc]initWithRootViewController:one];

    oneNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"笑脸[email protected]"] selectedImage:[UIImage imageNamed:@"笑脸[email protected]"]];


    twoViewController *two = [twoViewController new];

    UINavigationController *twoNav = [[UINavigationController alloc]initWithRootViewController:two];

    twoNav.tabBarItem= [[UITabBarItemalloc]initWithTitle:@"养牛宝"image:[UIImageimageNamed:@"笑脸[email protected]"]selectedImage:[UIImageimageNamed:@"笑脸[email protected]"]];


    threeViewController *three = [threeViewController new];

    UINavigationController *threeNav = [[UINavigationController alloc]initWithRootViewController:three];

    threeNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"" image:[UIImage imageNamed:@"笑脸[email protected]"] selectedImage:[UIImage imageNamed:@"笑脸[email protected]"]];


    fourViewController *four = [fourViewController new];

    UINavigationController *fourNav = [[UINavigationController alloc]initWithRootViewController:four];

    fourNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"绘牛咨询" image:[UIImage imageNamed:@"笑脸[email protected]"] selectedImage:[UIImage imageNamed:@"笑脸[email protected]"]];

    fiveViewController *five = [fiveViewController new];

    UINavigationController *fiveNav = [[UINavigationController alloc]initWithRootViewController:five];

    fiveNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"笑脸[email protected]"] selectedImage:[UIImage imageNamed:@"笑脸[email protected]"]];


    self.viewControllers=@[oneNav,twoNav,threeNav,fourNav,fiveNav];


    // Do any additional setup after loading the view.

}


在oneViewController.m中


导入#import "niuTableViewCell.h"

#import "zhexian.h"

并且 继承

uitableviewdelegate   uitableviewdatasouse  uisearchbardelegate

{

    NSArray*arr1;

}

@end

@implementationoneViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];


    UISearchBar*searchbar = [[UISearchBaralloc]initWithFrame:CGRectMake(FIT_X(10),FIT_X(20),SCR_W-FIT_X(30),FIT_X(20))];

    searchbar.delegate=self;


    [searchbarsetTintColor:[UIColor cyanColor]];


    [searchbarsetPlaceholder:@"搜索"];


//    [self.navigationController.]

    UIBarButtonItem* searchButton = [[UIBarButtonItemalloc]initWithCustomView:searchbar];


//    UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(15,80,SCR_W-100,30)];

//    titleView.backgroundColor = [UIColor cyanColor];

//    [self.view addSubview:titleView];


//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(fenshou)];

     self.navigationItem.rightBarButtonItem = searchButton;


    self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];

//    arr1 = @[@"image4.jpg",@"image4.jpg",@"image4.jpg",@"image4.jpg"];

    UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, FIT_X(400), SCR_W, FIT_X(250)) style:UITableViewStyleGrouped];

    table.delegate=self;

    table.dataSource=self;

    table.rowHeight=90;

    [self.viewaddSubview:table];


    zhexian*zhexianView = [[zhexianalloc]initWithFrame:CGRectMake(0,40,SCR_W,FIT_X(390))];

    [self.viewaddSubview:zhexianView];

}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

{

    return 10;

}

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

    staticNSString*reuse =@"cell";

    niuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];

    if(cell ==nil) {

        cell = [[niuTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];


    }

    cell.imageV.image= [UIImageimageNamed:@"image4.jpg"];

    cell.textL.text = @"当今最好的十大肉牛品种,我们该如何选择合适的肉牛品种";

    cell.detaL.text=@"中国养殖业联盟";

    cell.dateL.text=@"/6-19";

    returncell;

}

你可能感兴趣的:(作业)