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 ...
随机推荐
- thinkphp学习笔记7—多层MVC
原文:thinkphp学习笔记7-多层MVC ThinkPHP支持多层设计. 1.模型层Model 使用多层目录结构和命名规范来设计多层的model,例如在项目设计中如果需要区分数据层,逻辑层,服务层 ...
- JavaScript循环之for/in循环
今天学到了JavaScript的语句篇.同其他常见编程语言如C.Java等一样,JavaScript中的语句包含:①表达式语句②复合语句和空语句③声明语句④条件语句⑤循环语句⑥跳转语句,当然JavaS ...
- POJ 2502 Subway (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- JBoss7官方最新版下载地址
JBoss是全世界开发人员共同努力的成果,一个基于J2EE的开放源码的应用server. 由于JBoss代码遵循LGPL许可,能够在不论什么商业应用中免费使用它,而不用支付费用.2006年,Jboss ...
- ChartType属性
xl3DArea:三维面积图 xl3DAreaStacked:三维堆积面积图 xl3DAreaStacked100:三维堆积面积图 xl3DBarClustered:三维簇状条形图 xl3DBarSt ...
- php_公共方法01_传入数组_打印可见信息
function decodeUnicode($str) { return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'convert', $str ...
- 打破了中国电信华为无线路由猫(HG522-C)自己主动拨号+任意数量的计算机+iTV
中国电信路由猫去势后总是我的好E家里到处都是卖包(够坏垄断市场.有霸王条款多,例如,他们必须用自己的手机,同时计算机的最大数量的在线等),我曾破获另一家中国电信路由猫.非常easy,由U它磁盘恢复默认 ...
- WPF 辅助开发工具
原文:WPF 辅助开发工具 以下介绍的工具均为免费版,有些是源代码开放,希望对大家有用. Kaxaml 轻量级XAML 编辑器,可以同时进行图像和XAML 代码的编辑.最终生成开发人员想要的XAML ...
- 使用SignalR打造消息总线
使用SignalR为FineUI/Webform打造消息总线 第一次写博客,语言组织能力不好,请大家多多包涵! 效果图如下: 图片的右下角即为SignalR消息总线的消息框. 一.建立SignalR服 ...
- 开发现代ASP.NET应用程序
新思想.新技术.新架构——更好更快的开发现代ASP.NET应用程序(续1) 今天在@张善友和@田园里的蟋蟀的博客看到微软“.Net社区虚拟大会”dotnetConf2015的信息,感谢他们的真诚付 ...