UIView+Corner.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // UIView+Corner.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/9/28.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "UIView+Corner.h"
  9. @implementation UIView (Corner)
  10. - (void)setCorner {
  11. self.layer.cornerRadius = 10.0f;
  12. self.layer.masksToBounds = true;
  13. }
  14. - (void)setCornerIcon {
  15. self.layer.cornerRadius = 4.0f;
  16. self.layer.masksToBounds = true;
  17. }
  18. - (void)setShadow {
  19. self.layer.cornerRadius = 10.0f;
  20. self.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
  21. self.layer.shadowOffset = CGSizeMake(2,2);//shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0, -3),这个跟shadowRadius配合使用
  22. self.layer.shadowOpacity = 0.2;//阴影透明度,默认0
  23. self.layer.shadowRadius = 3;//阴影半径,默认3
  24. }
  25. - (UIView *)subViewOfClassName: (NSString *)className {
  26. for (UIView* subView in self.subviews) {
  27. if ([NSStringFromClass(subView.class) isEqualToString:className]) {
  28. return subView;
  29. }
  30. UIView* resultFound = [subView subViewOfClassName:className];
  31. if (resultFound) {
  32. return resultFound;
  33. }
  34. }
  35. return nil;
  36. }
  37. @end