前言
最近在转 Java ,想想研究 IOS 也一年有余了,总不能就这样荒废吧(貌似句话意思是想留点东西给什么人哦🙃,你懂得😝),现在在浦东地区的一个外包公司,闲暇之余,总结下 IOS 一些常用的技术资料,也算是对 IOS 开发的一个交代吧。闲话少说,步入正题
目前来说,官方共提供了两种方法来实现毛玻璃效果。
Method 1. UIToolbar (IOS7 以前)
创建一个 UIToolbar 实例,设置它的 frame 或者也可以通过添加约束,
然后 UIToolbar 有一个属性:barStyle,设置对应的枚举值来呈现毛玻璃的样式,
最后再添加到需要进行毛玻璃效果的 view 上即可
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@"犀牛"];
self.imageView = imageView;
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.imageView.frame.size.width * 0.5, _imageView.frame.size.height)];
/** UIBarStyle 毛玻璃的样式(枚举)
* UIBarStyleDefault = 0, // 浅色
* UIBarStyleBlack = 1, // 深色
* UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack
* UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES
*/
toolbar.barStyle = UIBarStyleBlackTranslucent;
[_imageView addSubview:toolbar];
Method 2. UIBlurEffect (IOS8.0 以后) - 推荐使用此方法
同样是先快速的实例化 UIBlurEffect 并设置毛玻璃的样式,
然后再通过 UIVisualEffectView 的构造方法将 UIBlurEffect 的实例添加上去,
最后设置 frame 或者是通过添加约束,将 effectView 添加到要实现了毛玻璃的效果的 view 控件上。
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@"犀牛"];
self.imageView = imageView;
/** UIBlurEffect 毛玻璃的样式(枚举)
* UIBlurEffectStyleExtraLight, // 极度白
* UIBlurEffectStyleLight, // 浅色
* UIBlurEffectStyleDark // 深色
*/
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
effectView.frame = CGRectMake(0, 0, _imageView.frame.size.width * 0.5, _imageView.frame.size.height);
[_imageView addSubview:effectView];
网友评论