欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS開發(fā)實現(xiàn)UIImageView的分類

 更新時間:2019年01月23日 15:44:57   作者:夕陽下的守望者  
這篇文章主要為大家詳細介紹了iOS開發(fā)實現(xiàn)UIImageView的分類,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了iOS實現(xiàn)UIImageView的分類代碼,供大家參考,具體內(nèi)容如下

一.Objective-C版

.h文件

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
 
/**
 * 這個分類為UIImageView添加一些有用的方法
 */
@interface UIImageView (WLKit)
 
/**
 * 創(chuàng)建一個UIImageView
 *
 * @param image UIImageView的圖片
 * @param rect UIImageView的坐標
 *
 * @return 返回一個UIImageView
 */
+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image
                   frame:(CGRect)rect;
 
/**
 * 創(chuàng)建一個UIImageView
 *
 * @param image UIImageView的圖片
 * @param size  UIImageView的大小
 * @param center UIImageView的中心
 *
 * @return 返回一個UIImageView
 */
+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image
                    size:(CGSize)size
                   center:(CGPoint)center;
 
/**
 * 創(chuàng)建一個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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS中UITableView使用的常見問題總結(jié)

    iOS中UITableView使用的常見問題總結(jié)

    這篇文章主要總結(jié)了iOS中UITableView使用的常見問題,其中包括如何設(shè)置headerView以及其高度、去掉多余cell的分割線 以及如何設(shè)置section數(shù)、行數(shù)等一系列的問題,文中介紹的更詳細,需要的朋友們下面來一起看看詳細介紹吧。
    2017-03-03
  • iOS base64 加密解密 通用類實例代碼

    iOS base64 加密解密 通用類實例代碼

    這篇文章主要介紹了iOS base64 加密解密 通用類的實例代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-12-12
  • IOS關(guān)閉鍵盤的方法

    IOS關(guān)閉鍵盤的方法

    在iOS應(yīng)用開發(fā)中,有三類視圖對象會打開虛擬鍵盤,進行輸入操作,但如何關(guān)閉虛擬鍵盤,卻沒有提供自動化的方法。這個需要我們自己去實現(xiàn)。
    2015-05-05
  • IOS實現(xiàn)點擊滑動抽屜效果

    IOS實現(xiàn)點擊滑動抽屜效果

    這篇文章主要為大家詳細介紹了IOS實現(xiàn)點擊滑動抽屜效果的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • iOS逆向教程之跟蹤函數(shù)調(diào)用詳解

    iOS逆向教程之跟蹤函數(shù)調(diào)用詳解

    這篇文章主要給大家介紹了關(guān)于iOS逆向教程之跟蹤函數(shù)調(diào)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • iOS如何獲取屏幕寬高、設(shè)備型號、系統(tǒng)版本信息

    iOS如何獲取屏幕寬高、設(shè)備型號、系統(tǒng)版本信息

    這篇文章主要介紹了iOS如何獲取屏幕寬高、設(shè)備型號、系統(tǒng)版本信息的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • iOS開發(fā)之TableView實現(xiàn)完整的分割線詳解

    iOS開發(fā)之TableView實現(xiàn)完整的分割線詳解

    在iOS開發(fā)中, tableView是我們最常用的UI控件之一。所以這篇文章主要給大家詳細介紹了關(guān)于iOS中的TableView分割線,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-12-12
  • IOS中Json解析實例方法詳解(四種方法)

    IOS中Json解析實例方法詳解(四種方法)

    本文將介紹TouchJson、 SBJson 、JSONKit 和 iOS5所支持的原生的json方法,解析國家氣象局API。通過本文給大家介紹IOS中Json解析的四種方法,非常不錯,具有參考借鑒價值,感興趣的朋友一起學(xué)習(xí)吧
    2016-06-06
  • IOS 出現(xiàn)問題POST網(wǎng)絡(luò)請求狀態(tài)code:500的解決方法

    IOS 出現(xiàn)問題POST網(wǎng)絡(luò)請求狀態(tài)code:500的解決方法

    這篇文章主要介紹了IOS 出現(xiàn)問題POST網(wǎng)絡(luò)請求狀態(tài)code:500的解決方法的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • iOS Crash常規(guī)跟蹤方法及Bugly集成運用詳細介紹

    iOS Crash常規(guī)跟蹤方法及Bugly集成運用詳細介紹

    這篇文章主要介紹了iOS Crash常規(guī)跟蹤方法及Bugly集成運用詳細介紹的相關(guān)資料,需要的朋友可以參考下
    2016-10-10

最新評論