工厂模式:

 
.h文件:
 
#import <Foundation/Foundation.h>
typedef enum{
    QFRed,
    QFYellow,
    QFBlue
}QFViewColor;

@interface QFview : UIView
+(id)viewWithColor:(QFViewColor)QFViewColorType;
@end

.m文件:
+(id)viewWithColor:(QFViewColor)QFViewColorType{
    UIView *view = [[UIView alloc] init];
    switch (QFViewColorType) {
        case QFRed:
            view.backgroundColor=[UIColor redColor];
            break;
        case QFYellow:
            view.backgroundColor=[UIColor yellowColor];
            break;
        case QFBlue:
            view.backgroundColor=[UIColor blueColor];
            break;
        default:
            view.backgroundColor=[UIColor whiteColor];
            break;
    }
    return view;
}
 
 
利用工厂模式显示view视图
 
    UIView *rootView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];
    rootView.backgroundColor = [UIColor whiteColor];
    
    rootView.clipsToBounds = YES;
    //切割视图外部的东西
    
    UIView *redView = [QFview viewWithColor:QFRed];
    redView.frame = CGRectMake(0, 0, 200, 200);
    [rootView addSubview:redView];
    redView.alpha = 1;
    
    UIView *yellowView = [QFview viewWithColor:QFYellow];
    yellowView.frame = CGRectMake(50, 50, 150, 150);
    yellowView.alpha = 1;
    [rootView addSubview:yellowView];
    
    UIView *blueView = [QFview viewWithColor:QFBlue];
    blueView.frame = CGRectMake(100, 100, 100, 100);
    [rootView addSubview:blueView];
    
 
图片显示:
 
对视图进行层次化操作:
 
    //[rootView bringSubviewToFront:redView];
    //[rootView sendSubviewToBack:blueView];
    
    NSArray *rootViewSubviews = rootView.subviews;
    int yellowIndex = [rootViewSubviews indexOfObject:yellowView];
    int redIndex = [rootViewSubviews indexOfObject:redView];
    
    //[rootView exchangeSubviewAtIndex:yellowIndex withSubviewAtIndex:redIndex];
    /* 将红色 黄色调换 */
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 50, 50)];
    greenView.backgroundColor = [UIColor greenColor];
    [rootView insertSubview:greenView aboveSubview:blueView];
    
    [self.window addSubview:rootView];
 
 
设置视图内的按键不可用
 
 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    button.frame = CGRectMake(50, 50, 50, 50);
    button.enabled = NO; //设置按键不可用
    [rootView addSubview:button];

    rootView.userInteractionEnabled = NO;
    //设置按键无法按下
    

 
制作动画:
 
 
代码如下:
 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 40, 300, 200)];
    imageView.backgroundColor = [UIColor redColor];
    //imageView.contentMode = UIViewContentModeScaleToFill;
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.animationDuration = 1.5;
    //速度多少秒
    NSMutableArray *images = [NSMutableArray array];
    for (int i=1; i<=13; ++i) {
        [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"png%d", i]]];
    
    }
    imageView.animationImages = images;
    //imageView.animationRepeatCount = 2;
    //图片重复多少次
    [imageView startAnimating];
    [self.window addSubview:imageView];
 
 
按钮可以换界面了、做四个界面每,按不同按钮切换不同界面:
 
 
 
代码:
 
 
#import "Xib.h"

@interface Xib ()
@property (weak, nonatomic) IBOutlet UIButton *button1;
@property (weak, nonatomic) IBOutlet UIButton *button2;
@property (weak, nonatomic) IBOutlet UIButton *button3;
@property (weak, nonatomic) IBOutlet UIButton *button4;
@property (weak, nonatomic) IBOutlet UIView *menuView;
-(void)showRedView;
-(void)showYellowView;
-(void)showBlueView;
-(void)showGreenView;
@end

@implementation Xib
{
    UIView *redView;
    UIView *yellowView;
    UIView *blueView;
    UIView *greenView;
}

- (IBAction)selected_one:(id)sender {
    _button1.selected = NO;
    _button2.selected = NO;
    _button3.selected = NO;
    _button4.selected = NO;

    UIButton *btn = sender;
    NSLog(@"点击:%d",btn.tag);

    btn.selected = YES;
    switch (btn.tag) {
        case 0:
            [self showRedView];
            break;
        case 1:
            [self showYellowView];
            break;
        case 2:
            [self showBlueView];
            break;
        case 3:
            [self showGreenView];
            break;
    }
}

-(void)showRedView{
    if (redView == nil) {
        redView = [[UIView alloc] initWithFrame:self.view.frame];
        redView.backgroundColor = [UIColor redColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
        label.text = @"The first page";
        [redView addSubview:label];
        [self.view addSubview:redView];
    }
    [self.view bringSubviewToFront:redView];
    [self.view bringSubviewToFront:self.menuView];
}

-(void)showYellowView
{
    if (yellowView == nil) {
        yellowView = [[UIView alloc] initWithFrame:self.view.frame];
        yellowView.backgroundColor = [UIColor yellowColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
        label.text = @"The second page";
        [yellowView addSubview:label];
        [self.view addSubview:yellowView];
    }
    [self.view bringSubviewToFront:yellowView];
    [self.view bringSubviewToFront:self.menuView];
}
-(void)showBlueView
{
    if (blueView == nil) {
        blueView = [[UIView alloc] initWithFrame:self.view.frame];
        blueView.backgroundColor = [UIColor blueColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
        label.text = @"The third page";
        [blueView addSubview:label];
        [self.view addSubview:blueView];
    }
    [self.view bringSubviewToFront:blueView];
    [self.view bringSubviewToFront:self.menuView];
}
-(void)showGreenView
{
    if (greenView == nil) {
        greenView = [[UIView alloc] initWithFrame:self.view.frame];
        greenView.backgroundColor = [UIColor greenColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
        label.text = @"The forth page";
        [greenView addSubview:label];
        [self.view addSubview:greenView];
    }
    [self.view bringSubviewToFront:greenView];
    [self.view bringSubviewToFront:self.menuView];
}

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.menuView.backgroundColor=[UIColor clearColor];
    // Do any additional setup after loading the view from its nib.
}

IOS UI 第三篇:基本UI的更多相关文章

  1. IOS设计模式第三篇之外观设计模式

    外观设计模式: 这个外观设计模式提供了一个单独的接口给复杂的子系统.而不是暴露用户的一组类和API,你仅仅暴露一个简单的同一的API. 下面的图片解释这个概念: API的用户根本不知道后面系统的复杂性 ...

  2. iOS开发UI篇—iOS开发中三种简单的动画设置

    iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...

  3. IOS UI 第八篇:基本UI

    实现图片的滚动,并且自动停止在每张图片上     - (void)viewDidLoad{    [super viewDidLoad]; UIScrollView *scrollView = [[U ...

  4. iOS进阶指南试读之UI篇

    iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...

  5. 四核驱动的三维导航—淘宝新UI(设计篇)

    前面有一篇博客说到了淘宝UWP的"四核驱动的三维导航—淘宝新UI(需求分析篇)",花了两周的时间实现了这个框架,然后又陆陆续续用了三周的时间完善它. 多窗口导航,与传统的导航方式的 ...

  6. firefox 扩展开发笔记(三):高级ui交互编程

    firefox 扩展开发笔记(三):高级ui交互编程 前言 前两篇链接 1:firefox 扩展开发笔记(一):jpm 使用实践以及调试 2:firefox 扩展开发笔记(二):进阶开发之移动设备模拟 ...

  7. 游戏模块分析总结(2)之UI、操作篇

    转自:http://www.gameres.com/309812.html 游戏模块分析总结(2)之UI.操作篇 发布者: wuye | 发布时间: 2014-12-12 15:03| 评论数: 0 ...

  8. 环信 之 iOS 客户端集成四:集成UI

    在Podfile文件里加入 pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-cocoapods.git' 然后在终端中的 ...

  9. vue mandmobile ui实现三列列表的方法

    vue mandmobile ui实现三列列表的方法 请问这种列表的要用那个组件好呢?Cellitem 只能用到两列,这个要三列的怎么弄?mand的好像没有listview,grid组件的 问了man ...

随机推荐

  1. Ansible@一个有效的配置管理工具--Ansible configure management--翻译(四)

    不要未经书面许可转载 第三章是长,因为,我会分几个部分来翻译. Advanced Playbooks So far the playbooks that we have looked at are s ...

  2. mongodb迁移

    A机器上有mongodb服务,A机器要废,于是迁至B. 简单起见,依旧是在A上ps auxwww|grep mongo找到正在执行的进程: /home/admin/mongodb/mongodb-li ...

  3. MySQL JDBC的queryTimeout坑

    遇到一个MySQL JDBC跑execute规定的方法queryTimeout坑,更恶心,无论是BUG,不能,^_^,为什么要说?请看下面的说明: 现象: 用同一个Connection运行大批量SQL ...

  4. 批处理命令 For循环命令具体解释!

    批处理for命令具体解释FOR这条命令基本上都被用来处理文本,但还有其它一些好用的功能!看看他的基本格式(这里我引用的是批处理中的格式,直接在命令行仅仅须要一个%号)FOR 參数 %%变量名 IN ( ...

  5. 第4章 建造者模式(Builder Pattern)

    原文 第4章 建造者模式(Builder Pattern) 定义 将一个复杂对象的构造与它的表示分离,使同样的构建过程可以创建不同的表示,这样的设计模式被称为建造者模式. 实用范围 1 当创建复杂对象 ...

  6. 利用缓存、Timer间隔时间发送微信的实例,很有用的例子

    //Class WechatOfferExcutor 此类为微信触发类,属于上层调用类,其中有用到用静态变量缓存offer信息,Task异步执行发送方法等 using Newtonsoft.Json. ...

  7. linux_安装 redis

    Installation Download, extract and compile Redis with: $ wget http://download.redis.io/releases/redi ...

  8. javascript获取浏览器窗口大小办法

    四个属性: 1:outerWidth  2:outerHeight  3:innerWidth  4:innerHeight 经最新版本的浏览器(Chrom IE Firefox Opera)测试,初 ...

  9. Microsoft Build 2015

    Microsoft Build 2015 汇总   简要概括(GitHub 完成约 45%): Visual Studio Code Preview Visual Studio 2015 RC Vis ...

  10. 【C语言的日常实践(十六)】字符串输出功能puts、fputs和printf

    C有三个标准库函数的输出字符串puts().fputs()和printf(). 1.puts()函数仅仅须要给出字符串參数的地址. #include <stdio.h> int puts( ...