一,效果图。

二,工程图。

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>
//头文件
#import "MoreView.h" @interface RootViewController : UIViewController
{
//是否点击
BOOL isSwitch;
//红色UIView界面
MoreView *moreView;
}
@end

RootViewController.m

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

MoreView.h

#import <UIKit/UIKit.h>

@interface MoreView : UIView

@end

MoreView.m

#import "MoreView.h"

@implementation MoreView

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code //设计背景色为红色
self.backgroundColor=[UIColor redColor];
}
return self;
} @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. Android中的FragmentManager的问题

    Fragment是构成灵活UI的重要部分.最近学习到Fragment的使用时候,碰到一个问题.主程序程序布局非常简单: <?xml version="1.0" encodin ...

  2. 使用Python进行GUI操作自动化

    前言 本文介绍怎样使用Python进行跨平台的GUI操作的,其中使用的一个工具包是pyautogui,PyAutoGUI可以模拟鼠标的移动.点击.拖拽,键盘按键输入.按住操作,以及鼠标+键盘的热键同时 ...

  3. helper实现隐藏前台特效

    想实现下面的功能:如下图所示 点击已结束按钮,使上面的红色跳转到已结束活动按钮上面,本来前台代码里面是使用了一个action来实现的,但是我改了点东西,使跳转不了. 前台代码 <ul class ...

  4. 【转载】async & await 的前世今生(Updated)

    async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们编程埋下了一些隐 ...

  5. javascript定时器,取消定时器,及js定时器优化方法

    通常用的方法: 启动定时器: window.setInterval(Method,Time) Method是定时调用的js方法 Time是间隔时间,单位是毫秒 取消定时器: clearInterval ...

  6. jquery选择器(综合)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. ajax携带状态值

  8. 使用MySQL WorkBench导入数据库

    1. 在MySQL WorkBench的Server Administrator中双击要连接的数据库: 2. 点击左边的Data Import/Restore; 3. Import from Dump ...

  9. PYTHON3连接MYSQL数据库

    http://smilejay.com/2013/03/python3-mysql-connector/ Python 2.x 上连接MySQL的库倒是不少的,其中比较著名就是MySQLdb(Djan ...

  10. Can't install mysql-python version 1.2.5 in Windows

    Can't install mysql-python version 1.2.5 in Windows http://stackoverflow.com/questions/37092125/cant ...