一,效果图。

二,工程图。

三,代码。

RootViewController.h

  1. #import <UIKit/UIKit.h>
  2. //头文件
  3. #import "MoreView.h"
  4.  
  5. @interface RootViewController : UIViewController
  6. {
  7. //是否点击
  8. BOOL isSwitch;
  9. //红色UIView界面
  10. MoreView *moreView;
  11. }
  12. @end

RootViewController.m

  1. //点击任何处,显示出红色的UIView
  2. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  3. {
  4. if (isSwitch) {
  5. [moreView removeFromSuperview];
  6. isSwitch=NO;
  7. }else{
  8. moreView=[[MoreView alloc]initWithFrame:CGRectMake(10, 100, 200, 50)];
  9. [self.view addSubview:moreView];
  10. isSwitch=YES;
  11. }
  12.  
  13. }

MoreView.h

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface MoreView : UIView
  4.  
  5. @end

MoreView.m

  1. #import "MoreView.h"
  2.  
  3. @implementation MoreView
  4.  
  5. - (id)initWithFrame:(CGRect)frame
  6. {
  7. self = [super initWithFrame:frame];
  8. if (self) {
  9. // Initialization code
  10.  
  11. //设计背景色为红色
  12. self.backgroundColor=[UIColor redColor];
  13. }
  14. return self;
  15. }
  16.  
  17. @end
 
 

【代码笔记】iOS-点击任何处,显示出红色的UIView的更多相关文章

  1. 【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  2. 【代码笔记】iOS-在导航栏中显示等待对话框

    一,效果图. 二,代码. ViewController.m #import "ViewController.h" @interface ViewController () @end ...

  3. 【代码笔记】iOS-点击搜索按钮,或放大镜后都会弹出搜索框

    一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "CLHSearchBar.h ...

  4. 【代码笔记】iOS-点击cell时候的动画翻转

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  5. 【代码笔记】iOS-点击顶点处,弹出另一个小的界面

    一,效果图. 二,文件目录. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...

  6. 【代码笔记】iOS-点击一个按钮会出现多个按钮的动画效果

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  7. 【代码笔记】iOS-点击任何处,出现城市

    一,效果图. 二,工程目录. 三,代码. //点击任何处,出现城市 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ...

  8. 【代码笔记】iOS-点击出现选择框

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  9. 【代码笔记】iOS-点击一个button,出6个button

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> //加入头文件 #import "DCPathB ...

随机推荐

  1. vue data对象添加新属性触发视图

    <template> <div class="wrap open"> <a>{{test01.name}}</a> <a> ...

  2. ASP.NET Core 开发-Logging 使用NLog 写日志文件

    ASP.NET Core 开发-Logging 使用NLog 写日志文件. NLog 可以适用于 .NET Core 和 ASP.NET Core . ASP.NET Core已经内置了日志支持,可以 ...

  3. iOS学习笔记——iOS高级控件

    UITableView UITableView的样式有两种,一种是Grouped(左图),另一种是Plain(右图),如下图,它的属性是style,类型为UITableViewStyle,枚举值分别是 ...

  4. 实现了IEnumerable接口的GetEnumerator 即可使用 Foreach遍历,返回一个IEnumerator对象

    #region 程序集 mscorlib.dll, v4.0.0.0 // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framewor ...

  5. Lua使用心得(1)

    这几天研究了一下lua,主要关注的是lua和vc之间的整合,把代码都写好放在VC宿主程序里,然后在lua里调用宿主程序的这些代码(或者叫接口.组件,随便你怎么叫),希望能用脚本来控制主程序的行为.这实 ...

  6. 扩展WPF的DataGrid按方向键移动焦点

    WPF的DataGrid默认的移动行为如下: (1)当前单元格不处于编辑状态时可使用方向键移动焦点. (2)当前单元格处于编辑状态时不可使用方向键移动焦点;按Enter键,当前单元格退出编辑状态,焦点 ...

  7. FNV哈希算法

    由来:FNV哈希算法全名为Fowler-Noll-Vo算法,是以三位发明人Glenn Fowler,Landon Curt Noll,Phong Vo的名字来命名的,最早在1991年提出. 特点和用途 ...

  8. 关于lr调用jar在vuser中可以运行,但是controller中却报错的问题

    如题,错误如下:javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilder ...

  9. 小白linux安装php 5.6+nginx配置(踩坑版)

    因为要搭建个知识库,直接用wordpress,这前提是得先装php,实在不喜欢XAMPP,所以自己折腾,没想到php这一来还不少啊,从头到尾折腾了一个小时多.记录下主要的流程和遇到的坑. 首先官网下载 ...

  10. Spring IoC源码解读——谈谈bean的几种状态

    阅读Spring IoC部分源码有一段时间了,经过不断的单步调试和参阅资料,对Spring容器中bean管理有了一定的了解.这里从bean的几个状态的角度出发,研究下IoC容器. 一.原材料 Xml中 ...