新浪微博的简易框架【主题选中特效】

在AppDelegate.m中设置根视图控制器

RootviewController.h

@interface RootTabbarController : UITabBarController
{
    UIImageView *_selectedImg;
}

RootviewController.m

#import "RootTabbarController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "PersonalViewController.h"
#import "DiscoverViewController.h"
#import "MoreViewController.h"

@interface RootTabbarController ()

@end

@implementation RootTabbarController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //创建三级控制器
    [self _initViewCtrls];

    //自定义标签视图
    [self _initTabbarView];
}

//创建三级控制器
- (void)_initViewCtrls {

    //1.创建一级控制器
    HomeViewController *homeCtrl = [[HomeViewController alloc] init];
    MessageViewController *messageCtrl = [[MessageViewController alloc] init];
    PersonalViewController *personalCtrl = [[PersonalViewController alloc] init];
    DiscoverViewController *discoverCtrl = [[DiscoverViewController alloc] init];
    MoreViewController *moreCtrl = [[MoreViewController alloc] init];

    NSArray *viewCtrls = @[homeCtrl,messageCtrl,personalCtrl,discoverCtrl,moreCtrl];

    //用于存放导航控制器
    NSMutableArray *navCtrls = [[NSMutableArray alloc] initWithCapacity:viewCtrls.count];

    //2.将视图控制器交给导航控制器控制
    for (int i=0; i<viewCtrls.count; i++) {
        //取出视图控制器
        UIViewController *viewCtrl = viewCtrls[i];
        UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:viewCtrl];
        [navCtrls addObject:navCtrl];
    }

    //3.创建三级控制器
    self.viewControllers = navCtrls;

}

//自定义标签视图
- (void)_initTabbarView {

    //1.移除tabbar上面的按钮
    NSArray *subView = [self.tabBar subviews];

    for (UIView *view in subView) {
        Class cla = NSClassFromString(@"UITabBarButton");

        if ([view isKindOfClass:cla]) {
            [view removeFromSuperview];
        }
    }

    //2.设置背景视图
    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"mask_navbar"]];

    //3.添加按钮
    for (int i=0; i<5; i++) {

        NSString *name = [NSString stringWithFormat:@"home_tab_icon_%d",i+1];

        //创建按钮
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
        button.tag = i;
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(64*i, (49-45)/2, 64, 45);
        [self.tabBar addSubview:button];
    }

    //4.添加选择按钮
    _selectedImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 45)];
    _selectedImg.image = [UIImage imageNamed:@"home_bottom_tab_arrow"];
    _selectedImg.backgroundColor = [UIColor clearColor];
    [self.tabBar addSubview:_selectedImg];

}

- (void)buttonAction:(UIButton *)button {

    //点击按钮切换试图
    self.selectedIndex = button.tag;
    //设置点击高亮的效果
    button.showsTouchWhenHighlighted = YES;

    //点击后选择的滑动效果
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:.35];
    _selectedImg.center = button.center;

    [UIView commitAnimations];

}
@end

HomeViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"首页";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //创建左侧的按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 130, 43);
    //设置背景图片
    UIImage *image = [UIImage imageNamed:@"button_title"];
    //设置拉伸点
    image = [image stretchableImageWithLeftCapWidth:50 topCapHeight:0];
    [leftButton setBackgroundImage:image forState:UIControlStateNormal];

    //创建一个image
    UIImageView *buttonImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 0, 44, 44)];
    buttonImageView.image = [UIImage imageNamed:@"button_icon_group"];
    buttonImageView.backgroundColor = [UIColor clearColor];
    [leftButton addSubview:buttonImageView];

    //创建一个label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 80, 44)];
    label.backgroundColor = [UIColor clearColor];
    label.text = @"我的微博";
    label.font = [UIFont boldSystemFontOfSize:17];
    label.textColor = [UIColor whiteColor];
    [leftButton addSubview:label];

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftItem;

    //创建右侧的按钮
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 0, 43, 43);
    //创建背景图片
    UIImage *bkImage = [UIImage imageNamed:@"button_m"];
    [rightButton setBackgroundImage:bkImage forState:UIControlStateNormal];
    [rightButton setImage:[UIImage imageNamed:@"button_icon_plus"] forState:UIControlStateNormal];

    UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightitem;

}

MessageViewController.m

PersonalViewController.m

DiscoverViewController.m

MoreViewController.m

#import "MoreViewController.h"
#import "ThemeViewController.h"

@interface MoreViewController ()

@end

@implementation MoreViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"更多";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //设置导航栏不穿透
    self.edgesForExtendedLayout = UIRectEdgeNone;

    //创建主题按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(10, 30, 300, 50);
    button.backgroundColor = [UIColor blueColor];
    [button setTitle:@"我的主题" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

}

- (void)buttonAction {

    ThemeViewController *themeCtrl = [[ThemeViewController alloc] init];

    [self.navigationController pushViewController:themeCtrl animated:YES];

}

ThemeViewController.h

@interface ThemeViewController : UIViewController
{
    UIImageView *_checkimg;
}

ThemeViewController.m

#import "ThemeViewController.h"

@interface ThemeViewController ()

@end

@implementation ThemeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        <span style="color:#cc0000;">self.hidesBottomBarWhenPushed = YES;</span>
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backcolor"]];
    self.view.backgroundColor = color;

    //创建子视图上侧的视图
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 106)];
    imageView.image = [UIImage imageNamed:@"topbg"];
    [self.view addSubview:imageView];

    //创建子视图
    for (int i=0; i<8; i++)
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *name = [NSString stringWithFormat:@"%d",i+1];
        [button setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];

        int row = i/2;

        if (i%2 == 0)
        {  //偶数
            button.frame = CGRectMake(5, 130+(62+5)*row, 150, 62);
        }
        else
        {  //奇数

            button.frame = CGRectMake(165, 130+(62+5)*row, 150, 62);
        }
        button.tag = i+100;
        //添加点击事件
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];

    }

    //通过tag去button
     UIButton *button = (UIButton *)[self.view viewWithTag:100];
    //创建选中标识图片
    _checkimg = [[UIImageView alloc] initWithFrame:CGRectMake(130+button.frame.origin.x, 40+button.frame.origin.y, 18, 18)];
    _checkimg.image = [UIImage imageNamed:@"checkmark"];
    [self.view addSubview:_checkimg];

}

- (void)viewWillAppear:(BOOL)animated
{

    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];

    [super viewWillAppear:animated];

}

- (void)viewWillDisappear:(BOOL)animated
{

    [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];

    [super viewWillDisappear:animated];

}

- (void)buttonAction:(UIButton *)button
{

   <span style="color:#cc0000;"> _checkimg.frame = CGRectMake(130+button.frame.origin.x, 40+button.frame.origin.y, 18, 18);</span>

}

@end
时间: 2024-10-11 22:08:45

新浪微博的简易框架【主题选中特效】的相关文章

仿Material UI框架的动画特效

Material UI是一款功能非常强大,界面却十分清新简洁的CSS框架,Material UI利用了Google的Material Design 全新设计语言,并且让每一个UI组件都变得非常独立,因此开发者使用Material UI也会比较简单.和Bootstrap类似,Material UI提供了很多常用的UI组件,除了最基本的菜单.按钮.滑动杆.进度条.单选框/复选框外,它还提供了一个非常有趣的日历组件,另外还提供了一些很有趣的图标. 不过,这里我并不打算介绍Material UI的使用,

iOS新浪微博开发系列--框架搭建

项目搭建 1.新建一个微博的项目,去掉屏幕旋转 2.设置屏幕方向-->只有竖向 3.使用代码构建UI,不使用storyboard 4.配置图标AppIcon和LaunchImage 将微博资料的相关素材拉到AppIcon和LaunchImage中,并将除了AppIcon和LaunchImage其它图片也全部拉到images.xcassets中. 项目布局 1.项目分层.为了让在Finder中显示跟Xcode中显示都是分层效果,首先在Finder中建文件目录,再拉到xcode中. 2.添加导航及控

github+hexo+themes搭建简易个性主题博客

0x00  install Node.js and git 安装Node.js:http://www.runoob.com/nodejs/nodejs-install-setup.html 安装git:下载地址:http://git-scm.com/download/ 0x01 安装Hexo 1.在D盘新建个hexo文件夹 $ cd d:/hexo $ npm install hexo-cli -g $ hexo init blog $ cd blog $ npm install $ hexo

学习.net core mvc 做的一个在线房间棋牌游戏微信支付和及时通讯简易框架

项目名称:游戏城(GameCitysSystem) 源代码github地址:https://github.com/antdesigner/appleGameSVN 开发工具:vs2017 数据库:mysql5.7 因为项目目前不完善,有一些注意事项 利用 "applegameData.sql" 文件初始化mysql数据库,数据库名称为 applegame 连接字符串在appsettings对应文件ConnectionStrings节点中配置 访问地址为: http://127.0.0:

Myjdbc反向代理简易框架

源码地址:https://github.com/beijing-penguin/Myjdbc 我为什么要写这个Myjdbc? 毕业后的一段时间一直在用hibernate,和mybatis框架,后来感觉这种框架太繁琐,比如,现在要用java读取客户给的一个excel表格,读取里面的数据后插入到数据库,这样一个小的需求,我都需要配置hibernate文件.配置mybatis的文件,对我来说,太麻烦了,因为我是懒人,不喜欢太多的东西,只喜欢简单易用就可以. 我记得有一次用hibernate框架管理多数

12、Django简易框架

安装: tar -zxvf Django-1.5.1.tar.gz cd Django-1.5.1 [[email protected] Django-1.5.1]# ls [[email protected] Django-1.5.1]# python setup.py install 查看版本 >>> import django >>> django.VERSION (1, 5, 1, 'final', 0) 创建一个project [[email protecte

MVC实战起步(一):一个简易框架的搭建

一:引言 这仅仅是一个新手写给新手共同入门的博文!这是一个使用MVC,和一些主流框架(Autofac,Log4Net等)来完成的一个简单的项目.和各位学习MVC的朋友们一起学习. 二:项目分层 如左图所示,先建好文件夹,然后再来填充内容. 一:Zero,MVC4.0项目 二:Domain: Abstract仓储类接口,Concrete仓储类实现,Entities实体模型 三:Infrastructure:基础设施 四:IOC:主要用于解耦仓储类接口 三:Infrastructure层建设 首先,

IBatis 简易框架搭建

1.练习框架 ibatis主要dll介绍 IBatisNet.Common.dll 由DataAccess和DataMapper组成的共享程序集 IBatisNet.Common.Logging.Log4Net.dll Log4Net集成记录器,和Log4Net配合使用 IBatisNet.DataMapper.dll DataMapper主要框架 IBatisNet.DataAccess.dll DataAccess框架 2.IBatisDao 1.DaoBase.cs Ibatis接口的封装

JQUERY实现的简单按钮轮换选中特效

<html> <head> <title>按钮轮换点击效果</title> <script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery.js"></script> </head> <style>  ul li{list-style-type:none;float:left;} &