Files
mier_ios/SweetParty/Expand/YBKit/UIView+YBUtil.m
2025-08-11 10:43:19 +08:00

74 lines
2.5 KiB
Objective-C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UIView+EasyShadow.m
// secert
//
// Created by binbins on 2019/5/7.
// Copyright © 2019 binbins. All rights reserved.
//
#import "UIView+YBUtil.h"
@implementation UIView (YBUtil)
- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = YES;
}
- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}
- (void)styleShadow {
self.layer.shadowColor =COLOR16(0x333333).CGColor;
self.layer.shadowOffset = CGSizeMake(0.7, 0.7);
self.layer.shadowOpacity = 0.28;
self.layer.borderWidth = 0.0001f; //圆角和阴影共存的关键
self.layer.masksToBounds = NO;
// self.layer.cornerRadius = 10;
}
- (void)styleShadowWithRedius:(CGFloat)redius {
self.layer.shadowColor = HEXCOLORA(0xCB8BFB, 0.24).CGColor;
self.layer.shadowOffset = CGSizeMake(0, 2);
self.layer.shadowOpacity = 1;
self.layer.borderWidth = 0.0001f; //圆角和阴影共存的关键
self.layer.masksToBounds = NO;
self.layer.cornerRadius = redius;
}
- (void)homeShadowWithRadius:(CGFloat)redius {
self.layer.shadowColor = [HEXCOLOR(0x5E3EB5) colorWithAlphaComponent:0.04].CGColor;
self.layer.shadowOffset = CGSizeMake(0.5, 0.5);
self.layer.shadowOpacity = 1;
self.layer.borderWidth = 0.0001f; //圆角和阴影共存的关键
self.layer.masksToBounds = NO;
self.layer.cornerRadius = redius;
}
- (UIImage *)renderImage {
// 下面方法第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果需要传NO否则传YES。第三个参数就是屏幕密度了关键就是第三个参数 [UIScreen mainScreen].scale。
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, [UIScreen mainScreen].scale);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (UIViewController *)viewController {
for (UIView *view = self; view; view = view.superview) {
UIResponder *nextResponder = [view nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
- (void)styleGradiBlueColor {
self.backgroundColor = [UIColor bm_colorGradientChangeWithSize:self.size direction:FXGradientChangeDirectionHorizontal startColor:mainLightColor endColor:mainDeepColor];
}
@end