zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-点击任何处,显示出红色的UIView

    一,效果图。

    二,工程图。

    三,代码。

    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
    复制代码

     

     

     
     
  • 相关阅读:
    集合(5)—Map之HashMap()
    《转》python 10 集合
    《转》python8元组
    《转》python(7)列表
    《转》python数据类型
    《转》python对象
    《转》python
    《转》python基础下
    《转》python学习基础
    《转》python 9 字典,numpy
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5123267.html
Copyright © 2011-2022 走看看