loadNibNamed:(NSString *)name owner:(nullable id)owner options:(nullable NSDictionary *)options用法
1.name xib的名字 owner当前类对象 options初始参数
实际应用:
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"***" owner:self options:nil];
nibs[0]是当前view的对象 nibs[1]当前view的背景 ,我们可以在init中对当前frame以及当前view的背景的frame进行赋值, nibs[1]的背景是半透明的,如果当前的xib是View,把view添加到父对象的时候nibs[1]没有添加到父空间,则当前的view是全透明的,
举个例子:这个是我创建的xib

该xib对应的initWith
-(instancetype)initWithCancleButtonTitle:(NSString *)cancelTitle otherButtonTitle:(NSString *)otherTitle
{
CGRect frame = CGRectMake(0, 0, Main_Screen_Width-40, 180);
self = [super initWithFrame:frame];
if (self) { NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"***" owner:self options:nil];
self = nibs[0];
self.frame = CGRectMake(0, 0, Main_Screen_Width-40, 180); coverView = nibs[1];
[self setUIController]; if (rect.size.height > 54) {
self.frame = CGRectMake(0, 0, Main_Screen_Width-40, 180);
}
[self.cancleButton setTitle:cancelTitle forState:UIControlStateNormal];
[self.otherButton setTitle:otherTitle forState:UIControlStateNormal];
}
return self;
}
-(void)setUIController{
coverView.frame = CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height);
coverView.backgroundColor = [UIColor redColor];
self.layer.cornerRadius = 4.0;
self.layer.masksToBounds = YES;
[self.cancleButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[self.otherButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
_line1.backgroundColor = [UIColor grayColor];
_line2.backgroundColor = [UIColor grayColor];
}
把当前view添加到window上:
UIWindow *window = [UIApplication sharedApplication].keyWindow;
self.center = CGPointMake(Main_Screen_Width/2, Main_Screen_Height/2);
[window addSubview:coverView]; [window addSubview:self];

红色的view是半透明的,如果 [window addSubview:coverView];去掉的效果

loadNibNamed:(NSString *)name owner:(nullable id)owner options:(nullable NSDictionary *)options用法的更多相关文章
- SELECT s.* FROM person p INNER JOIN shirt s ON s.owner = p.id WHERE p.name LIKE 'Lilliana%' AND s.color <> 'white';
SELECT s.* FROM person p INNER JOIN shirt sON s.owner = p.idWHERE p.name LIKE 'Lilliana%'AND s.color ...
- /etc/named/named.conf.options中的Options参数
listen-on port 53 { any; }; 监听在这部主机系统上面的哪个网路介面.预设是监听在localhost,亦即只有本机可以对DNS 服务进行查询,那当然是很不合理啊!所以这里要将大 ...
- 自定义控件CustomAlertView
[记录][完整代码最下] 效果如下: 可行性分析: 由于系统自带的UIAlertView样式简单,只有两种样式,想要理想的样式就要自定义控件了 文件名取为:CustomAlertView 创建文件如下 ...
- 【原】AFNetworking源码阅读(一)
[原]AFNetworking源码阅读(一) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 AFNetworking版本:3.0.4 由于我平常并没有经常使用AFNetw ...
- AFNetworking 3.0 源码解读(六)之 AFHTTPSessionManager
AFHTTPSessionManager相对来说比较好理解,代码也比较短.但却是我们平时可能使用最多的类. AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilit ...
- iOS---观察者模式之--->KVO
文章结构如下: Why? (为什么要用KVO) What? (KVO是什么) How? ( KVO怎么用) More (更多细节) 原理 自己实现KVO 在我的上一篇文章浅谈 iOS Notifica ...
- AVPlayer
AVPlayer AVPlayerLayer是CALayer的一个子类,由于AVPlayer这个播放器只能安置在AVPlayerLayer 这个图层之上,所以我们需要实例化一个UIView,并 ...
- KVO内部实现原理
KVO的原理: 只要给一个对象注册一个监听, 那么在运行时, 系统就会自动给该对象生成一个子类对象, (格式如:NSKVONotifying_className), 并且重写自动生成的子类对象的被监听 ...
- iOS开发——UI基础-KVO
KVO == Key Value Observing 作用: 可以监听某个对象属性的改变 一.使用KVO Person *p = [Person new]; p.name = @"chg&q ...
随机推荐
- 【python】\\u的字符编码问题
Str = "\\u559c\\u6b22\\u4e00\\u4e2a\\u4eba";Str = Str.decode("unicode-escape")
- Linux使用expect实现自动登录的脚本
前提条件服务器已经安装过tcl和expect, 若未安装:可以先执行 yum install tcl expect 进行安装 第一步.编写以下自动登录脚本login.sh ########### ...
- 【Matlab】运动目标检测之“光流法”
光流(optical flow) 1950年,Gibson首先提出了光流的概念,所谓光流就是指图像表现运动的速度.物体在运动的时候之所以能被人眼发现,就是因为当物体运动时,会在人的视网膜上形成一系列的 ...
- CSS Sprite的应用
什么是CSS Sprite ? 不知道您在浏览yahoo.com的网页中是否注意到,yahoo在页面制作上的技术和大多数网站不一样,他们把页面上的 ICON,栏目背景啊,图片按钮啊等都有会有规则的合并 ...
- css hack整理 (摘)
CSS Hack Table Y 渲染 N 不渲染 H 部分版本或部分属性渲染 B 样式失效 windows Mobile Linux Mac IE Firefox Chrome Safa ...
- mysql show processlist 命令检查mysql lock
processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 1. 进入mysql/bin目录下输入mysqladmin processlist; ...
- JS-在线运行代码小工具
原理:window.open()方法,open一个新的空白页,然后把文本框中粘贴的代码通过DOM操作,写到新的代码页中, 再利用document.write的功能(写进去之前把其他的全部删掉,并且写进 ...
- 【BZOJ3280】小R的烦恼 最小费用最大流
[BZOJ3280]小R的烦恼 Description 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要求小R帮助他一起解决一个难题. 问题是这样的 ...
- 【BZOJ4101】[Usaco2015 Open]Trapped in the Haybales Silver 二分
[BZOJ4101][Usaco2015 Open]Trapped in the Haybales (Silver) Description Farmer John has received a sh ...
- 在linux下安装Avria(小红伞)
1.下载AntiVir PersonalEdition Classic for linux http://www.free-av.com/ 2.解压: tar zxvf antivir.tar.gz ...