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];
![](http://images.cnitblog.com/blog/418829/201403/311936307661148.jpg)
//[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;
//设置按键无法按下
![](http://images.cnitblog.com/blog/418829/201403/311936325632963.jpg)
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];
![](http://images.cnitblog.com/blog/418829/201403/311936341105937.jpg)
@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 ...
随机推荐
- 问题(bug)确实不在代码逻辑上面,往往是配置、权限或者业务逻辑之外的地方(转)
不能说所有的bug都是纸老虎,但往往那种看似很奇葩的bug,导致的原因确实很简单,烦了你一段时间,找到真相又让你忍不住一笑.什么是奇葩的bug呢.我的定义是:代码逻辑都一样,但在A处是好的,到了B处就 ...
- 如何构建高性能web网站:分布式缓存
一.数据库前端缓冲区 要清除数据库前缓冲区,首先必须明确什么是文件系统的内核缓冲区(Buffer Area):它位于内核的物理内存地址空间,除了使用O_DIRECT比其他标签中打开文件,所有的磁盘的读 ...
- linux_shell_根据网站来源分桶
应用场景: 3kw行url+\t+html记录 [网站混合] 需要:按照网站来源分桶输出 执行shell cat */*pack.html|awk -F '\t' '{ split($1,arr,&q ...
- keil程序在外部RAM中调试的问题总结(个人的一点经验总结)
keil程序在内部RAM调试的基本步骤网上已经有非常多了,我就不再赘述,大家能够在网上搜到非常多. 可是有些时候内部RAM并不够用,这就须要将程序装入外部RAM中调试,而在这个过程中可能会出现各种各样 ...
- Scriptcase演示程序,现在,他们使用SC多么简单的开发系统
Scriptcase它内置了一批成熟的业务系统,我们的系统的一部分已经完成和功能微调,在互联网上.检查每个人Scriptcase如何简单可以加速的功能模块的发展. 访问 http://www.phps ...
- HDU 5068 Harry And Math Teacher
主题链接~~> 做题情绪:的非常高深,有种高大上的感觉. 解题思路: 两层之间的联通能够看成是一个矩阵 代表上下两层都能够联通,,代表下层第1个门与上层第一个门不联通,以此类推联通就能够用矩阵 ...
- 如何完成Nexus 9上电后激活过程
所述被激活,因为它是Nexus 9经过努力获得启动OTA最新更新包,而且因为Google关闭一堵墙.原因无法下载更新包. 因为是第一次开机,它不能被设置usb debugging, 无法adb去杀死w ...
- iOS发展 - 使用您自己的自定义字体
一位同事问我最后一次,XXapp字体如何萌啊? 我也想提出萌哒哒的字体!然后,今天有这blog. 首先,我们正处于iOS发展,苹果给了我们很多的字体,当然,我就不一一列举在这里,英文,小汤表示看不懂啦 ...
- 关于UtilTimerStack类的使用--XWork2、Struts2内置性能诊断类
关于UtilTimerStack类的使用--XWork2.Struts2内置性能诊断类 一.UtilTimerStack做什么用的? 这个本来是Xwork2(Struts2的核心)的相关的工具类,可以 ...
- springMVC 获取本地项目路径 及后整理上传文件的方法
String path=request.getSession().getServletContext().getRealPath("upload/img/product"); // ...