国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS開發實現UIImageView的分類

2020-07-26 02:21:41
字體:
來源:轉載
供稿:網友

本文實例為大家分享了iOS實現UIImageView的分類代碼,供大家參考,具體內容如下

一.Objective-C版

.h文件

#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>#import <QuartzCore/QuartzCore.h> /** * 這個分類為UIImageView添加一些有用的方法 */@interface UIImageView (WLKit) /** * 創建一個UIImageView * * @param image UIImageView的圖片 * @param rect UIImageView的坐標 * * @return 返回一個UIImageView */+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image                   frame:(CGRect)rect; /** * 創建一個UIImageView * * @param image UIImageView的圖片 * @param size  UIImageView的大小 * @param center UIImageView的中心 * * @return 返回一個UIImageView */+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image                    size:(CGSize)size                   center:(CGPoint)center; /** * 創建一個UIImageView * * @param image UIImageView的圖片 * @param center UIImageView的中心 * * @return Returns the created UIImageView */+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image                   center:(CGPoint)center; /** * Create an UIImageView with an image and use it as a template with the given color * * @param image   UIImageView image * @param tintColor UIImageView tint color * * @return Returns the created UIImageView */+ (instancetype _Nonnull)imageViewWithImageAsTemplate:(UIImage *_Nonnull)image                      tintColor:(UIColor *_Nonnull)tintColor; /** * Create a drop shadow effect * * @param color  Shadow's color * @param radius Shadow's radius * @param offset Shadow's offset * @param opacity Shadow's opacity */- (void)setImageShadowColor:(UIColor *_Nonnull)color           radius:(CGFloat)radius           offset:(CGSize)offset          opacity:(CGFloat)opacity; /** * Mask the current UIImageView with an UIImage * * @param image The mask UIImage */- (void)setMaskImage:(UIImage *_Nonnull)image; @end

.m文件

#import "UIImageView+WLKit.h" @implementation UIImageView (WLKit) + (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image frame:(CGRect)rect{  UIImageView *_image = [[UIImageView alloc] init];  [_image setFrame:rect];  [_image setImage:image];  return _image;} + (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image size:(CGSize)size center:(CGPoint)center{  UIImageView *_image = [[UIImageView alloc] init];  [_image setFrame:CGRectMake(0, 0, size.width, size.height)];  [_image setImage:image];  [_image setCenter:center];  return _image;} + (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image center:(CGPoint)center{  UIImageView *_image = [[UIImageView alloc] init];  [_image setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];  [_image setImage:image];  [_image setCenter:center];  return _image;} + (instancetype _Nonnull)imageViewWithImageAsTemplate:(UIImage *_Nonnull)image tintColor:(UIColor *_Nonnull)tintColor{  UIImageView *_image = [[UIImageView alloc] init];  image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];  [_image setImage:image];  [_image setTintColor:tintColor];  return _image;} - (void)setImageShadowColor:(UIColor *_Nonnull)color radius:(CGFloat)radius offset:(CGSize)offset opacity:(CGFloat)opacity{  self.layer.shadowColor = color.CGColor;  self.layer.shadowRadius = radius;  self.layer.shadowOffset = offset;  self.layer.shadowOpacity = opacity;  self.clipsToBounds = NO;} - (void)setMaskImage:(UIImage *_Nonnull)image{  CALayer *mask = [CALayer layer];  mask.contents = (id)[image CGImage];  mask.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);  self.layer.mask = mask;  self.layer.masksToBounds = YES;} - (void)setAlpha:(CGFloat)alpha{  if ([self.superview isKindOfClass:[UITableView class]]) {    if (self.superview.tag == 836913) {      if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) {        if (self.frame.size.width < 10 && self.frame.size.height > self.frame.size.width) {          UIScrollView *sc = (UIScrollView*)self.superview;          if (sc.frame.size.height < sc.contentSize.height) {            [super setAlpha:0.5];            return;          }        }      }    }        if (self.superview.tag == 836914) {      if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) {        if (self.frame.size.height < 10 && self.frame.size.height < self.frame.size.width) {          UIScrollView *sc = (UIScrollView*)self.superview;          if (sc.frame.size.width < sc.contentSize.width) {            return;          }        }      }    }  }    [super setAlpha:alpha];}@end

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 饶平县| 临江市| 同心县| 津南区| 县级市| 沂源县| 平度市| 苏尼特左旗| 鸡西市| 电白县| 阳朔县| 德庆县| 建始县| 资源县| 建平县| 高阳县| 黄大仙区| 阿图什市| 仁布县| 武宁县| 崇信县| 万山特区| 三门县| 寿光市| 建瓯市| 宁南县| 桑日县| 东莞市| 达州市| 永顺县| 鄂尔多斯市| 丰顺县| 丹东市| 黔西| 商都县| 乃东县| 西和县| 巴林左旗| 南川市| 定结县| 江口县|