首页 > 其他 > 详细

【代码笔记】点击任何处,显示出红色的UIView

时间:2016-01-12 10:00:18      阅读:223      评论:0      收藏:0      [点我收藏+]

一,效果图。

技术分享

二,工程图。

技术分享

三,代码。

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
技术分享

 

 

 
 

【代码笔记】点击任何处,显示出红色的UIView

原文:http://www.cnblogs.com/yang-guang-girl/p/5123267.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!