工厂模式:

.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.
}

转载于:https://www.cnblogs.com/firstrate/p/3636698.html

IOS UI 第三篇:基本UI相关推荐

  1. Android面试系列文章2018之内存管理之UI卡顿篇

    Android面试系列文章2018之内存管理之UI卡顿篇 1.UI卡顿的原理   60ftp –> 16ms: Android系统每隔16ms都会对界面进行渲染一次,造成卡顿的原因就是Andro ...

  2. iOS SwiftUI篇-2 UI控件 Text Button Image List

    iOS SwiftUI篇-2 UI控件 Text Button Image List Text 显示文本,相当于UILabel import SwiftUIstruct TextContentView ...

  3. ASP.NET 数据分页第三篇 - 结合 Custom Control 处理 GridView 的 UI 呈现

     延续本系列前两篇帖子「ASP.NET 数据分页第一篇 - 探讨分页原理及 SQL Server 2005 的 ROW_NUMBER 函数」.「ASP.NET 数据分页第二篇 - 范例下载」,本系列的 ...

  4. android 界面组件,安卓开发学习周第三篇——Android中的UI组件

    原标题:安卓开发学习周第三篇--Android中的UI组件 在Android APP中,所有的用户界面元素都是由View和ViewGroup的对象构成的.View是绘制在屏幕上的用户能与之交互的一个对 ...

  5. UI实战教程之切图标注篇(UI小白必备)

    UI实战教程之切图标注篇(UI小白必备) 一. 切图工具和标注工具 学会使用工具可以起到事半功倍的效果.在这里为大家推荐我常用的切图和标注工具. 1. 切图工具: (1)Cutterman 这是一款运 ...

  6. 分享一套超棒的iOS “空状态” (empty state) 界面UI设计

    日期:2013-2-1  来源:GBin1.com 大家在程序开发或者界面设计中常常会遇到这样一些情况: 404 error 内容未找到 账户余额不够 文件没有找到 等等 这 些典型的属于empty ...

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

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

  8. iOS 9人机界面指南(一):UI设计基础

    [ISUX译]iOS 9人机界面指南(一):UI设计基础 raina2015.10.29 文章索引 1.1 为iOS而设计(Designing for iOS) 1.1.1 设计跟随内容 (Defer ...

  9. “四核”驱动的“三维”导航 -- 淘宝新UI(需求分析篇)

    "四核"驱动的"三维"导航 -- 淘宝新UI(需求分析篇) 原文:"四核"驱动的"三维"导航 -- 淘宝新UI(需求分析 ...

最新文章

  1. 科普丨人工智能发展的S曲线
  2. 六、MySql索引分类
  3. 有关糖尿病模型建立的论文_预测糖尿病结果的模型比较
  4. C语言头文件 “ 细节 ”
  5. leetcode —— 面试题67. 把字符串转换成整数
  6. 三星Galaxy S21 FE即将量产:8月登场 小屏满血旗舰!
  7. Win-MASM64汇编语言-MOV/MOVSB/MOVSW/MOVSD/REP/REPZ/REPE/REPNZ/REPNE
  8. JavaScript 详解:为什么写好的代码非常重要
  9. C++传递数组给函数
  10. 简单的学生库管理系统
  11. python之slice,range
  12. Linux 安装 MySQL 以及 一些常见问题解决方案
  13. magisk核心功能模式是什么_HRT-Lin-荣耀V9 B347 自动接听Xposed 机型 Magisk 桌面设置 dpi等功能...
  14. 某大学校园网设计方案大学校园拓扑图 全解
  15. matlab插值函数的作用,matlab 插值函数
  16. Excel鼠标所在行列填充颜色
  17. 证券公司信息化4_最核心的IT系统是什么?柜台系统的两个主要功能?一个交易过程是怎样的?
  18. 思科模拟器 --- 路由器静态路由配置
  19. Android Studio 使用友盟进行多渠道打包
  20. Apache Tomcat UTF-8编码漏洞[转载至邪恶八进制]

热门文章

  1. 在Project中引用zedgraph控件
  2. 速度最快250fps!实时、高性能车道线检测算法LaneATT
  3. Nature调查再聚焦读博压力:超1/3博士生焦虑抑郁,大学有没有能哭的地方?
  4. 百万奖金!天池发起广东工业制造创新大赛
  5. gitlable iphone_iPhone 12首批用户成“小白鼠”,“信号故障”躺枪者无数
  6. Java面试问题汇总(Redis)
  7. 边缘AI计算新时代,人工神经网络秒变脉冲神经网络
  8. 目标检测的二十年发展史—从传统方法到深度学
  9. 关于numpy mean函数的axis参数
  10. 桁架机器人运动视频_CUBIC桁架式机器人被广泛应用的原因