一,效果图。二,工程图。三,代码。RootViewController.h#import <UIKit/UIKit.h>//头文件#import "MoreView.h"@interface RootViewController : UIViewC ...
一,效果图。
二,工程图。
三,代码。
RootViewController.h
//点击任何处,显示出红色的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
#import "MoreView.h"@implementation MoreView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code //设计背景色为红色 self.backgroundColor=[UIColor redColor]; } return self;}@end
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:【代码笔记】点击任何处,显示出红色的UIView
关键词:ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。