美文网首页开发编程iOS-Vendor
主流APP基本骨架的快速搭建

主流APP基本骨架的快速搭建

作者: Tuberose | 来源:发表于2015-09-01 20:37 被阅读3146次
  • 在许多我们日常使用的应用中,我们会发现,他们的界面骨架(或者说样子)基本相同
    • 像QQ,简书,微博等


  • 他们有一个相似的基本界面骨架是这样子的:
  • 首先,界面有一些什么组成
  • TabBar上切换不同的导航控制器(界面),NavigationBar上点击BarButtonItem跳转(push)到下一个界面

  • 那么这样的基本界面骨架,我们如何去搭建呢?

iPhone项目开始时候要处理注意的地方

  • APP的名称设置


搭建流程思考

  • 1.自定义TabBarController

    • 添加四个子控制器
    • 设置好四个子控制器的相关属性(TabBarItem内部图片和文字的设置)
  • 2.自定义NavigationController(重写push:方法,封装返回键)

    • 这里的返回键的封装(设置)是很有用也很常见的,也很方便,掌握了,今后直接在项目中拿出来用就可以了
    • 但这里是先搭建基本骨架。有关总结在我的另外一篇文章《项目开发中封装一个返回键--很实用》《项目开发中封装一个BarButtonItem类别-很实用》
  • 我们这里界面的搭建可以选择storyboard搭建,但这种情况一般是界面比较少的情况下选用。

  • 当我们的界面很多,到时候要各种进行界面间跳转的时候,我们仍然使用storyboard搭建的话,要是几十个控制器之间的跳转,眼睛都看花你的。

  • 所以界面多得时候,我们选择代码创建

  • 这里我将选择代码创建,让大家知道一个大概的思路


  • 在AppDelegate.m文件中重新创建,而不会使用Main.storyboard.
  • 先创建根控制器

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 1.创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;

    // 2.设置窗口的根控制器
    self.window.rootViewController = [[CYTabbarController alloc] init];

    // 3.显示窗口
    [self.window makeKeyAndVisible];

    return YES;
}
  • 新建一个(自定义)TabBarController
#import "CYTabbarController.h"

@interface CYTabbarController ()

@end

@implementation CYTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];

    // UIControlStateNormal情况下的文字属性
    NSMutableDictionary *normalAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    normalAtrrs[NSForegroundColorAttributeName] = [UIColor grayColor];

    // UIControlStateSelected情况的文字属性
    NSMutableDictionary *selectedAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    selectedAtrrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];


    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAtrrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];

    // 添加四个子控制器
    UIViewController *vc1 = [[UIViewController alloc] init];
    vc1.tabBarItem.title = @"精华";
    vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
    vc1.view.backgroundColor = [UIColor greenColor];
    [self addChildViewController:vc1];

    UIViewController *vc2 = [[UIViewController alloc] init];
    vc2.tabBarItem.title = @"新帖";
    vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
    vc2.view.backgroundColor = [UIColor grayColor];
    [self addChildViewController:vc2];

    UIViewController *vc3 = [[UIViewController alloc] init];
    vc3.tabBarItem.title = @"关注";
    vc3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    vc3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    vc3.view.backgroundColor = [UIColor blueColor];
    [self addChildViewController:vc3];

    UIViewController *vc4 = [[UIViewController alloc] init];
    vc4.tabBarItem.title = @"我";
    vc4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    vc4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
    vc4.view.backgroundColor = [UIColor yellowColor];
    [self addChildViewController:vc4];
}


@end
  • 这样就创建成功了,你说快不快!
  • 当然不可能代码这么多,下面我会进行抽取
  • 运行式样:

代码的抽取

#import "CYTabbarController.h"

@interface CYTabbarController ()

@end

@implementation CYTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 开始抽取代码了:
    [self setUpItem];
    [self setUpChildVc];
 

/**
 *  设置Item的属性
 */
- (void)setUpItem
{
    // UIControlStateNormal情况下的文字属性
    NSMutableDictionary *normalAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    normalAtrrs[NSForegroundColorAttributeName] = [UIColor grayColor];

    // UIControlStateSelected情况的文字属性
    NSMutableDictionary *selectedAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    selectedAtrrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];

    // 统一给所有的UITabBatItem设置文字属性
    // 只有后面带有UI_APPEARANCE_SELECTOR方法的才可以通过appearance来设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAtrrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];
}

/**
 *  设置setUpChildVc的属性,添加所有的子控件
 */
- (void)setUpChildVc
{
    [self setUpChildVc:[UIViewController class]  title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self setUpChildVc:[UIViewController class]  title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    [self setUpChildVc:[UIViewController class]  title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    [self setUpChildVc:[UIViewController class]  title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
//    // 添加四个子控制器
//    UIViewController *vc1 = [[UIViewController alloc] init];
//    vc1.tabBarItem.title = @"精华";
//    vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
//    vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
//    vc1.view.backgroundColor = [UIColor greenColor];
//    [self addChildViewController:vc1];
//
//    UIViewController *vc2 = [[UIViewController alloc] init];
//    vc2.tabBarItem.title = @"新帖";
//    vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
//    vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
//    vc2.view.backgroundColor = [UIColor grayColor];
//    [self addChildViewController:vc2];
//
//    UIViewController *vc3 = [[UIViewController alloc] init];
//    vc3.tabBarItem.title = @"关注";
//    vc3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
//    vc3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
//    vc3.view.backgroundColor = [UIColor blueColor];
//    [self addChildViewController:vc3];
//
//    UIViewController *vc4 = [[UIViewController alloc] init];
//    vc4.tabBarItem.title = @"我";
//    vc4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
//    vc4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
//    vc4.view.backgroundColor = [UIColor yellowColor];
//    [self addChildViewController:vc4];
}

- (void)setUpChildVc:(Class)vcClass title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    UIViewController *vc = [[UIViewController alloc] init];
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    // 创建一个随机色
    vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
    [self addChildViewController:vc];
}
@end
  • 在微博和简书APP中在TabBar中间有一个加号按钮,用于发布或者别的功能
  • 那么这么重要的一个按钮,我们如何实现呢?
    • 首先,上面系统的TabBar是满足不了我们了,所以我们只能自定义一个TabBar
    • 自定义TabBar后,就要开始在上面进行子控件的布局,修改他们的位置了
    • 重写initWithFrame:方法以及LayoutSubViews:方法,布局子控件
  • 在自定义的CYTabBarController中
//
//  CYTabbarController.m
//  聪颖不聪颖
//  Copyright (c) 2015年 congying. All rights reserved.
//

#import "CYTabbarController.h"
#import "CYEssenceViewController.h"
#import "CYFocusViewController.h"
#import "CYPublishViewController.h"
#import "CYNewPostViewController.h"
#import "CYMeViewController.h"
#import "CYTabBar.h"
#import "CYNavigationController.h"

@interface CYTabbarController ()

@end

@implementation CYTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 开始抽取代码了:
    
    // 抽取Item属性
    [self setUpItem];

    // 布局子控件
    [self setUpChildVc];
    
    // 处理tabBar
    [self setUpTabBar];
    
}
/**
 *  处理tabBar
 */
- (void)setUpTabBar
{
    [self setValue:[[CYTabBar alloc] init] forKey:@"tabBar"];
}

/**
 *  设置Item的属性
 */
- (void)setUpItem
{
    // UIControlStateNormal情况下的文字属性
    NSMutableDictionary *normalAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    normalAtrrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    // UIControlStateSelected情况的文字属性
    NSMutableDictionary *selectedAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    selectedAtrrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    // 统一给所有的UITabBatItem设置文字属性
    // 只有后面带有UI_APPEARANCE_SELECTOR方法的才可以通过appearance来设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAtrrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];
}

/**
 *  设置setUpChildVc的属性,添加所有的子控件
 */
- (void)setUpChildVc
{
    [self setUpChildVc:[[CYEssenceViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self setUpChildVc:[[CYNewPostViewController alloc] init] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    [self setUpChildVc:[[CYFocusViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    [self setUpChildVc:[[CYMeViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}

- (void)setUpChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 包装一个导航控制器
    CYNavigationController *nav = [[CYNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    // 设置子控制器的tabBarItem
    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:image];
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    nav.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
}



@end
  • 自定义一个TabBar
#import "CYTabBar.h"

@interface CYTabBar()
/** 增加发布按钮*/
@property (nonatomic, weak) UIButton *publishButton;
@end

@implementation CYTabBar


- (instancetype) initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        // 设置背景图片
        self.backgroundImage = [UIImage imageNamed:@"tabbar-light"];

        UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [publishButton sizeToFit];
        // 监听按钮点击(发布按钮)
        [publishButton addTarget:self action:@selector(publishClick) forControlEvents:UIControlEventTouchUpInside];
        //        publishButton.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);
        [self addSubview:publishButton];
        self.publishButton = publishButton;

    }
    return self;
}
- (void)publishClick
{
    NSLog(@"%s",__func__);
}


/**
 *  重写layoutSubviews方法,布局子控件
 */
- (void)layoutSubviews
{
    [super layoutSubviews];

    // TabBar的尺寸
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    // 设置发布按钮的位置
    self.publishButton.center = CGPointMake(width * 0.5, height * 0.5);

    // 设置索引
    int index = 0;
    // 按钮的尺寸
    CGFloat tabBarButtonW = self.frame.size.width / 5;
    CGFloat tabBarButtonH = self.frame.size.height;
    CGFloat tabBarButtonY = 0;

    // 设置四个TabBarButton的frame
    for (UIView *tabBarButton in self.subviews) {
        if (![NSStringFromClass(tabBarButton.class) isEqualToString:@"UITabBarButton"]) continue;

        // 计算按钮X的值
        CGFloat tabBarButtonX = index * tabBarButtonW;

        if (index >= 2) {
            tabBarButtonX += tabBarButtonW; // 给后面2个button增加一个宽度的X值
        }
        tabBarButton.frame = CGRectMake(tabBarButtonX, tabBarButtonY, tabBarButtonW, tabBarButtonH);
        index++;

    }
}

一些细节方面的注意处理以及一些补充:

  • TabBarItem内部图片和文字的设置
  • 为什么要设置呢:
    • 因为不设置的话,苹果就会自动将它渲染成蓝色,而不是我们(客户)想要的样式
  • 图标高亮和正常状态是如何设置它本身的颜色
    • Xcode中设置,一劳永逸
  • 代码实现方式(了解一下,知道的办法多一点毕竟不是坏事):
    //    UIImage *tempImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
    //    UIImage *selectedImage = [tempImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    vc1.tabBarItem.selectedImage = selectedImage;
    vc1.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabBar_essence_click_icon" ]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 这里的设置可以不让系统给图片渲染成蓝色
  • 如何设置TabBarItem的文字颜色呢?只能代码了
// UIControlStateNormal情况下的文字属性
    NSMutableDictionary *normalAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    normalAtrrs[NSForegroundColorAttributeName] = [UIColor grayColor];

    // UIControlStateSelected情况的文字属性
    NSMutableDictionary *selectedAtrrs = [NSMutableDictionary dictionary];
    // 文字颜色
    selectedAtrrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];


    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAtrrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];

换肤

  • 通过设置appearance来进行换肤,一设置,全部控件都跟着变
  • 但是有条件:
    // 统一给所有的UITabBatItem设置文字属性
    // 只有后面带有UI_APPEARANCE_SELECTOR方法的才可以通过appearance来设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAtrrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtrrs forState:UIControlStateSelected];
  • 控制器之间的关系
  • 由上图的关系可以知道下面注释的代码与没注释的代码效果是一样的
    // 包装一个导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];

    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:image];
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    nav.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];

//    vc.tabBarItem.title = title;
//    vc.tabBarItem.image = [UIImage imageNamed:image];
//    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
//    vc.view.backgroundColor = [UIColor 
colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
  • 代码抽取里的代码严谨点替换成下面的代码

/**
 *  设置setUpChildVc的属性,添加所有的子控件
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    [self setUpChildVc:[[CYEssenceViewController alloc] init]  title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self setUpChildVc:[[CYNewPostViewController alloc] init]  title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    [self setUpChildVc:[[CYFocusViewController  alloc] init]  title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    [self setUpChildVc:[CYMeViewController alloc]  title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}

    // 包装一个导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];

    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:image];
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    nav.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
}
  • 下面两种方法都可以传图片
    // 这样传图片,它传的图片尺寸和原始尺寸一样
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MainTitle"]];
    // 这两种方法所实现的效果是一样的,但是很明显用上面的
//    UIImageView *titleView = [[UIImageView alloc] init];
//    titleView.image = [UIImage imageNamed:@"MainTitle"];
//    [titleView sizeToFit];
//    self.navigationItem.titleView = titleView;
  • 打印(获取)window的三种方法:
NSLog(@"%@ %@ %@", self.view.superview, self.view.window, [UIApplication sharedApplication].keyWindow);
  • 创建一个随机色
nav.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
  • 小小注意点:
    self.title =@"我的关注";
    相当于下面两句
    self.navigationItem.title = @"我的关注";
    self.tabBarItem.title = @"我的关注";

一般在公司项目开始开发时候,你在公司会给你下面相关文档

  • API\接口文档

  • 作用

    • 跟服务器进行交互的文档
  • 格式

    • HTML网页
    • word文档
  • 开发进度文档

    • 任务\进度
  • 需求文档

    • 有哪些模块
    • 有哪些功能
    • 大致的界面
  • 原型图

    • 详细的界面描述
    • 界面的跳转关系

  • 源码地址:https://github.com/Tuberose621/-APP-
  • 界面之间跳转后的返回键如何巧妙的设置呢?
  • 已经封装好了,在另外的文章中有--《项目开发中封装一个返回键--很实用》《项目开发中封装一个BarButtonItem类别-很实用》

相关文章

  • 主流APP基本骨架的快速搭建

    在许多我们日常使用的应用中,我们会发现,他们的界面骨架(或者说样子)基本相同像QQ,简书,微博等 他们有一个相似的...

  • 一 、实战脚手架搭建-创建项目基本骨架

    1.实战脚手架搭建-创建项目基本骨架 1.1 快速创建 Spring Boot 项目 目录如下 pom 文件如下<...

  • react基本操作回顾

    1.基本语法 1.1快速搭建 Cnpm i -g create-react-appCreate-react-app...

  • iOS 主流APP的搭建

    看着身边的朋友都在写技术博客,我也谈不上什么技术大牛.也只是一个晚辈.所以大多还是自己平时开发中遇到问题的一些总结...

  • iOS总结篇(一)

    小型APP项目快速搭建基本流程 一个月开发一个APP,应该很正常,但是一周开发一个简单的app,应该也还行! ...

  • mall整合SpringBoot+MyBatis搭建基本骨架

    本文主要讲解mall整合SpringBoot+MyBatis搭建基本骨架,以商品品牌为例实现基本的CRUD操作及通...

  • Pinax (Django 2.0.2 快速搭建骨架)

    它就是一个Django开发骨架,方便我们快速搭建一个网站 参考地址 pip install pinax-cli ...

  • hexo 搭建个人博客

    利用hexo在github上快速搭建个人博客 方案选型 主流的三种博客搭建方案: 我的选择: Git+Github...

  • iOS 搭建一个App框架

    主流的方式搭建一个App框架 先看效果图 UITabBarController实现底部按钮本文章的内容为:学会搭建...

  • 搭建2016主流APP框架

    1.新建项目 2.基础文件配置 (1)Project根目录:编辑.gitignore、创建.jks签名、编辑bui...

网友评论

  • Kimball:最近思考微博那个发布按钮怎么实现的,看到后豁然开朗! :+1:
  • 弹钢琴的安徒生:又看了一下。的确写的很不错 对于我这种初学者挺好的。除了小部分代码有点冗余 其他都很nice 但不失为一篇好博客
    Tuberose:@弹钢琴的安徒生 THX
  • 弹钢琴的安徒生:添加子控制器哪里抽个方法就更好了
  • 林辉Alfred:下面那些细节的 不被渲染的直接用tintcolor好像就能直接改图标和文字的颜色了
    Tuberose:@林辉Alfred 对
  • GJCode:谢谢您。很帮,我学习了
    Tuberose:@GJCode 😄
  • 买了否冷_:很详细,很棒!
  • 多喝热水z:感谢分享
  • 3e858b85c36f:有源码么?
    3e858b85c36f:@Tuberose 代码抽取里的代码严谨点替换成下面的代码
    这句话下面的代码少了方法名 - (void)setUpChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
    3e858b85c36f:@Tuberose 好的 谢谢了
    Tuberose:@这冬天不会冷 这个你不需要源码就可以做的,源代码已经贴在上面了,估计需要控件图片。下一个简书的APP,解压缩,获取包内容,就可以拿到APP里的各种控件图片,找差不多的按钮图片,你就可以做了!
  • _笑口常开:很好,谢谢!
    Tuberose:@小小瑞 😊😊😊
  • seongbrave:大神咨询您个问题, 您自定义了一个CYTabBar 类,然后怎么把自定义的类给替换了CYTabBarController这个类的呢?CYTabBar应该是继承自UITabBar吧,CYTabBarController继承自UITabBarController?
    Tuberose:@seongbrave 首先,感谢给我提的问题。因为确实是怪我,在自定义TabBar时,忘贴上了CYTabBarController.m文件的代码(也是醉了,感谢!)。在其中应该用KVC传值:[self setValue:[[CYTabBar alloc] init] forKey:@"tabBar"];然后就是只读属性问题。并没有完全只读的属性,它是系统做了一层处理,当我们用KVC的时候,也是可以拿到相应的值,就像你问题中的那样。还有就像iOS开发中启用运行时RunTime,是可以拿到某个类所有的成员变量,属性,方法等东西。而有一些底层的我们平时是拿不到的。恩,就只能这么回答你了!是在下输了 :grin: :grin: :grin:
    seongbrave:@Tuberose 我知道TabBarController 包含了TabBar啊,@property(nonatomic,readonly) UITabBar *tabBar ,源码显示只读的一个属性,所以我是说怎么把自定义的CYTabBar 设置到CYTabBarController这了呢?
    Tuberose:@seongbrave 首先,你后面两个问题是正确的。然后有关于第一个问题:你要清楚TabBarController和TabBar的关系。TabBarController包含了TabBar,TabBar是TabBarController的一个子控件。在开发中,当我们的需求就像我文中提到TabBar要加一个发布按钮的时候。用系统的肯定满足不了我们的要求。这个时候就需要自定义一个TabBar了。去重写它的initWithFrame:和layoutSubviews:方法去重新布局子控件的位置,以达到我们的需求。如果没有特殊要求一般就不需要重新自定义了,用系统的就OK了。
  • 830f18dc4f7b:谢谢你。
  • 王大先森:很棒,谢谢你咯…挺清晰的

本文标题:主流APP基本骨架的快速搭建

本文链接:https://www.haomeiwen.com/subject/smllcttx.html