IOS UI 第三篇:基本UI
工厂模式:
typedef enum{
QFRed,
QFYellow,
QFBlue
}QFViewColor;
@interface QFview : UIView
+(id)viewWithColor:(QFViewColor)QFViewColorType;
@end
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;
}
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 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];
button.frame = CGRectMake(50, 50, 50, 50);
button.enabled = NO; //设置按键不可用
[rootView addSubview:button];
rootView.userInteractionEnabled = NO;
//设置按键无法按下

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];

@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的更多相关文章
- IOS设计模式第三篇之外观设计模式
外观设计模式: 这个外观设计模式提供了一个单独的接口给复杂的子系统.而不是暴露用户的一组类和API,你仅仅暴露一个简单的同一的API. 下面的图片解释这个概念: API的用户根本不知道后面系统的复杂性 ...
- iOS开发UI篇—iOS开发中三种简单的动画设置
iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...
- IOS UI 第八篇:基本UI
实现图片的滚动,并且自动停止在每张图片上 - (void)viewDidLoad{ [super viewDidLoad]; UIScrollView *scrollView = [[U ...
- iOS进阶指南试读之UI篇
iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...
- 四核驱动的三维导航—淘宝新UI(设计篇)
前面有一篇博客说到了淘宝UWP的"四核驱动的三维导航—淘宝新UI(需求分析篇)",花了两周的时间实现了这个框架,然后又陆陆续续用了三周的时间完善它. 多窗口导航,与传统的导航方式的 ...
- firefox 扩展开发笔记(三):高级ui交互编程
firefox 扩展开发笔记(三):高级ui交互编程 前言 前两篇链接 1:firefox 扩展开发笔记(一):jpm 使用实践以及调试 2:firefox 扩展开发笔记(二):进阶开发之移动设备模拟 ...
- 游戏模块分析总结(2)之UI、操作篇
转自:http://www.gameres.com/309812.html 游戏模块分析总结(2)之UI.操作篇 发布者: wuye | 发布时间: 2014-12-12 15:03| 评论数: 0 ...
- 环信 之 iOS 客户端集成四:集成UI
在Podfile文件里加入 pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-cocoapods.git' 然后在终端中的 ...
- vue mandmobile ui实现三列列表的方法
vue mandmobile ui实现三列列表的方法 请问这种列表的要用那个组件好呢?Cellitem 只能用到两列,这个要三列的怎么弄?mand的好像没有listview,grid组件的 问了man ...
随机推荐
- Git与TortoiseGit基本操作(转)
1. GitHub操作 本节先简单介绍 git 的使用与操作, 然后再介绍 TortoiseGit 的使用与操作. 先看看SVN的操作吧, 最常见的是 检出(Check out ...), 更新 (U ...
- FFmpeg资料来源简单分析:libswscale的sws_getContext()
===================================================== FFmpeg库函数的源代码的分析文章: [骨架] FFmpeg源码结构图 - 解码 FFmp ...
- HDU ACM 1007 Quoit Design 分而治之的方法,最近点
意甲冠军:给n坐标点.半一对点之间的距离所需的距离最近. 分析:分而治之的方法,最近点. #include<iostream> #include<algorithm> #inc ...
- NYNU_省赛选拔题(10)
题目描述 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recog ...
- C# 带用户密码访问网络共享
原文:C# 带用户密码访问网络共享 调用WNetUseConnection API 函数详细参数参考:https://msdn.microsoft.com/en-us/library/windows/ ...
- hdu 游乐场
Problem Description 小时候,因为家里经济困难,小明从未去过游乐场,所以直到现在,他还心存遗憾. 最近,杭州刚建了一座游乐场,为了弥补儿时的遗憾,小明带了一笔钱迫不及待地要去体 ...
- WebService返回DataTable问题
今天做项目时,想在WebService中返回DataTable,在单位没成功,看网上有人说datable在.net1.1中是没有序列化的,不能直接在webservice中返回,可以返回dataset. ...
- 【百度地图API】建立全国银行位置查询系统(一)——如何创建地图
原文:[百度地图API]建立全国银行位置查询系统(一)--如何创建地图 <摘要>你将在第一章中学会以下知识: 如何创建一个网页文件 怎样利用百度地图API建立一张2D地图,以及3D地图 如 ...
- vistual studio 2012 安装失败,提示Microsoft Vistual Studio 2012 Devenv找不到元素,等错误信息
在安装vistual studio 2012过程中,出现安装失败,提示Microsoft Vistual Studio 2012 Devenv找不到元素,等错误信息 解决方法是更新相应的server补 ...
- Linux学习笔记——怎样在交叉编译时使用共享库
0.前言 在较为复杂的项目中会利用到交叉编译得到的共享库(*.so文件).在这样的情况下便会产生下面疑问,比如: [1]交叉编译时的共享库是否须要放置于目标板中,假设须要放置在哪个文件 ...