美文网首页
UIView类别

UIView类别

作者: 猪队友小L | 来源:发表于2017-08-19 11:20 被阅读22次
#import <UIKit/UIKit.h>

@interface UIView (Extension_1)

+ (UIView *)viewWithFrame:(CGRect)frame
          backgroundColor:(UIColor *)backgroundColor;

- (UIViewController *)viewController;

//毛玻璃
+ (UIVisualEffectView *)effectViewWithFrame:(CGRect)frame;

@end


#import "UIView+Extension_1.h"

@implementation UIView (Extension_1)

+ (UIView *)viewWithFrame:(CGRect)frame
          backgroundColor:(UIColor *)backgroundColor
{
    UIView *view =[[UIView alloc]initWithFrame:frame];
    view.backgroundColor =backgroundColor;
    return view;
}

- (UIViewController *)viewController{
    UIResponder *next = self.nextResponder;
    do {
        if ([next isKindOfClass:[UIViewController class]]) {
            
            return (UIViewController *)next;
        }
        next = next.nextResponder;
        
    } while (next != nil);
    return nil;
}

+ (UIVisualEffectView *)effectViewWithFrame:(CGRect)frame
{
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = frame;
    return effectView;
}

@end

相关文章

网友评论

      本文标题:UIView类别

      本文链接:https://www.haomeiwen.com/subject/efktdxtx.html