广告
返回顶部
首页 > 资讯 > 移动开发 >iOS开发实现UIImageView的分类
  • 566
分享到

iOS开发实现UIImageView的分类

iOSUIImageView分类 2022-05-22 06:05:18 566人浏览 薄情痞子
摘要

本文实例为大家分享了iOS实现UIImageView的分类代码,供大家参考,具体内容如下 一.Objective-C版 .h文件 #import <Foundation/F

本文实例为大家分享了iOS实现UIImageView的分类代码,供大家参考,具体内容如下

一.Objective-C版

.h文件


#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
 

@interface UIImageView (WLKit)
 

+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image
                   frame:(CGRect)rect;
 

+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image
                    size:(CGSize)size
                   center:(CGPoint)center;
 

+ (instancetype _Nonnull)imageViewWithImage:(UIImage *_Nonnull)image
                   center:(CGPoint)center;
 

+ (instancetype _Nonnull)imageViewWithImageAsTemplate:(UIImage *_Nonnull)image
                      tintColor:(UIColor *_Nonnull)tintColor;
 

- (void)setImageShadowColor:(UIColor *_Nonnull)color
           radius:(CGFloat)radius
           offset:(CGSize)offset
          opacity:(CGFloat)opacity;
 

- (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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: iOS开发实现UIImageView的分类

本文链接: https://www.lsjlt.com/news/30225.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • iOS开发实现UIImageView的分类
    本文实例为大家分享了iOS实现UIImageView的分类代码,供大家参考,具体内容如下 一.Objective-C版 .h文件 #import <Foundation/F...
    99+
    2022-05-22
    iOS UIImageView 分类
  • iOS开发实现抽屉效果
    iOS开发之如何实现“抽屉”效果,供大家参考,具体内容如下 现在基本上每一个App中左划都会出现一个页面,基本上都是只占主页面的一部分,效果就像是一个抽屉一样...
    99+
    2022-11-13
    iOS 抽屉
  • iOS开发实现搜索框(UISearchController)
    最近自己在写一个APP,其中需要实现搜索框搜索功能,于是乎就想写篇博客介绍下UISearchController和搜索框的实现。 我写的是一个天气预报APP,直接以我APP中的源代码...
    99+
    2022-11-13
    iOS 搜索框 UISearchController
  • iOS开发实现转盘功能
    本文实例为大家分享了iOS实现转盘功能的具体代码,供大家参考,具体内容如下 今天给同学们讲解一下一个转盘选号的功能,直接上代码直接看 ViewController #pragm...
    99+
    2022-05-27
    iOS 转盘
  • iOS开发实现计算器功能
    本文实例为大家分享了iOS实现计算器功能的具体代码,供大家参考,具体内容如下 效果图 Masonry 使用数组来自动约束 NSArray *buttonArrayOne = @...
    99+
    2022-05-28
    iOS 计算器
  • iOS开发UICollectionView实现拖拽效果
    一.介绍 iOS9提供API实现单元格排序功能,使用UICollectionView及其代理方法。iOS9之后有自带方法可以实现该效果,只需添加长按手势,实现手势方法和调用iOS9的...
    99+
    2022-05-23
    iOS UICollectionView 拖拽
  • IOS Ble蓝牙开发实现方法
    本篇博文阐述如何开发Ble蓝牙。在蓝牙中的一些常见服务,扫描,以及链接; 主蓝牙类文件.h 主蓝牙类文件.m UUID文件 蓝牙列表展示的文件 一:引入Bl...
    99+
    2022-05-30
    IOS Ble 蓝牙
  • iOS开发KVO实现细节解密
    目录导读1. 缘起 Aspects1.1 SDMagicHook 的 API 设计更加友好灵活1.2 SDMagicHook 解决了 Aspects 未能解决的 KVO 冲突难题2....
    99+
    2022-11-13
    iOS开发KVO细节 iOS KVO
  • Android实现类似iOS分栏控制器
    近公司接了一个项目,需要会安卓,人手不够的情况作为一个开发iOS的也需要跟进,开始学习android,集成开发环境以后。直接就被难到了,iOS里面的分栏控制器(tabbarcontr...
    99+
    2022-11-13
  • Android开发仿IOS滑动开关实现代码
    Android开发仿IOS滑动开关实现代码Android与iOS相比,ios好多控件都是自带的,而android需要使用自定义来实现。今天说的是ios的滑动开关,我层看到好多博客都是通过自定义ToggleButton实现的。这里我通过自定义...
    99+
    2023-05-31
    android ios 滑动开关
  • iOS开发实现图片浏览功能
    本文实例为大家分享了iOS实现图片浏览功能的具体代码,供大家参考,具体内容如下 这是整体的效果图: 其中main.stroyboard中的控件有2个button,2个label,一...
    99+
    2022-11-13
  • iOS开发实现简单抽屉效果
    本文实例为大家分享了iOS实现简单抽屉效果的具体代码,供大家参考,具体内容如下 抽屉效果的原理:其实就是把两个子控制器添加到一个RootViewController中,将子控制器的v...
    99+
    2022-11-13
    iOS 抽屉
  • iOS开发中的几个手势操作实例分享
    手势操作---识别单击还是双击 在视图上同时识别单击手势和双击手势的问题在于,当检测到一个单击操作时,无法确定是确实是一个单击操作或者只是双击操作中的第一次点击。解决这个问题的方法就...
    99+
    2022-05-26
    iOS 手势
  • iOS开发实现简单计算器功能
    用Object-C写的一个简单的计算机程序,主要学习按钮的action动作。 下面是主界面: 下面代码时界面按钮和ViewController.h连接的地方: - (IBActio...
    99+
    2022-11-13
  • iOS开发中的touchesBegan触摸事件怎么实现
    在iOS开发中,可以通过重写`touchesBegan`方法来处理触摸事件。`touchesBegan`方法会在用户触摸屏幕时被调用...
    99+
    2023-09-14
    iOS
  • iOS开发中实现显示gif图片的方法
    我们知道Gif是由一阵阵画面组成的,而且每一帧画面播放的时常可能会不相等,观察上面两个例子,发现他们都没有对Gif中每一帧的显示时常做处理,这样的结果就是整个Gif中每一帧画面都是以...
    99+
    2022-05-19
    ios gif
  • iOS开发中怎么实现多参数传递
    在iOS开发中,可以通过以下几种方式实现多参数传递:1. 使用NSDictionary或NSMutableDictionary:将多...
    99+
    2023-09-14
    iOS
  • iOS开发中实现邮件和短信发送的简单示例
    发送邮件 1.导入库文件:MessageUI.framework 2.引入头文件 3.实现代理<MFMailComposeViewControllerDelegate> ...
    99+
    2022-05-26
    iOS 邮件 短信
  • iOS开发实战之Label全方位对齐的轻松实现
    前言 本文主要给大家介绍了关于iOS Label全方位对齐的实现方法,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 ARUILabelTextAlign 实现 ...
    99+
    2022-05-19
    ios label 对齐
  • iOS 11开发中iOS11模拟器的示例分析
    这篇文章将为大家详细讲解有关iOS 11开发中iOS11模拟器的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。iOS11模拟器介绍在图1.6或者1.7中所看到的类似于手机的模型就是iOS模拟器。i...
    99+
    2023-06-04
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作