最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2019年01月23日 15:44:57   作者:夕陽下的守望者  
這篇文章主要為大家詳細(xì)介紹了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的坐標(biāo)
 *
 * @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如何定義名為任意的變量詳解

    iOS如何定義名為任意的變量詳解

    這篇文章主要給大家介紹了關(guān)于iOS如何定義名為任意的變量的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-05-05
  • iOS 定制多樣式二維碼

    iOS 定制多樣式二維碼

    最常見的二維碼功能包括信息獲取、網(wǎng)站跳轉(zhuǎn)、電商交易、手機支付等等,其擁有密度小、信息容量大、容錯能力強、成本低、制作難度低等優(yōu)點。在移動開發(fā)中,二維碼的地位也越來越重要,掌握二維碼的基本操作是重要的本領(lǐng)之一。本文將講解iOS定制二維碼的步驟與方法。
    2017-03-03
  • CAMediaTiming ( 時間協(xié)議)詳解及實例代碼

    CAMediaTiming ( 時間協(xié)議)詳解及實例代碼

    這篇文章主要介紹了CAMediaTiming / 時間協(xié)議詳解及實例代碼的相關(guān)資料,這里附有實例代碼,幫助大家學(xué)習(xí)參考,需要的朋友可以參考下
    2016-12-12
  • CocoaPods1.9.0 安裝使用教程詳解

    CocoaPods1.9.0 安裝使用教程詳解

    CocoaPods是OS X和iOS下的一個第三類庫管理工具,這篇文章主要介紹了CocoaPods1.9.0 安裝使用,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-03-03
  • iOS WKWebView無法處理URL Scheme和App Store鏈接的問題解決

    iOS WKWebView無法處理URL Scheme和App Store鏈接的問題解決

    這篇文章主要給大家介紹了關(guān)于iOS WKWebView無法處理URL Scheme和App Store鏈接的問題解決的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • iOS開發(fā)之使用Storyboard預(yù)覽UI在不同屏幕上的運行效果

    iOS開發(fā)之使用Storyboard預(yù)覽UI在不同屏幕上的運行效果

    使用Storyboard做開發(fā)效率非常高,為了防止在團(tuán)隊中發(fā)生沖突,采取的解決辦法是負(fù)責(zé)UI開發(fā)的同事最好每人維護(hù)一個Storyboard, 公用的組件使用輕量級的xib或者純代碼來實現(xiàn),下面小編就給大家介紹如何使用Storyboard預(yù)覽UI在不同屏幕上的運行效果,需要的朋友可以參考下
    2015-08-08
  • ios常見加密解密方法(RSA、DES 、AES、MD5)

    ios常見加密解密方法(RSA、DES 、AES、MD5)

    本篇文章主要介紹了ios常見加密解密方法(RSA、DES 、AES、MD5),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • iOS使用pageViewController實現(xiàn)多視圖滑動切換

    iOS使用pageViewController實現(xiàn)多視圖滑動切換

    這篇文章主要為大家詳細(xì)介紹了iOS使用pageViewController實現(xiàn)多視圖滑動切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • iOS客戶端本地推送實現(xiàn)代碼

    iOS客戶端本地推送實現(xiàn)代碼

    這篇文章主要介紹了iOS客戶端本地推送實現(xiàn)代碼,并確定程序中只有一個彈出框,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • iOS開發(fā)之級聯(lián)界面(推薦界面)搭建原理

    iOS開發(fā)之級聯(lián)界面(推薦界面)搭建原理

    這篇文章主要為大家詳細(xì)介紹了iOS級聯(lián)界面(推薦界面)搭建原理,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08

最新評論

日照市| 襄樊市| 麦盖提县| 离岛区| 那曲县| 白山市| 湛江市| 西城区| 文安县| 沙湾县| 花莲市| 玉树县| 大竹县| 南乐县| 从化市| 兴安盟| 封丘县| 石台县| 石首市| 榕江县| 保山市| 静宁县| 望都县| 濉溪县| 普兰店市| 安达市| 盈江县| 友谊县| 个旧市| 邵东县| 新津县| 玉树县| 申扎县| 五指山市| 岗巴县| 桓台县| 法库县| 韶关市| 绥江县| 双柏县| 西林县|