美文网首页
iOS图片拉伸

iOS图片拉伸

作者: 新生代农民工No1 | 来源:发表于2021-06-23 13:13 被阅读0次

前言:在开发工程中,设计给的图不能完全满足我们的需求,所以有时就需要我们根据需求自己去处理;

整体拉伸:
通过设置UIImageView的属性contentMode;

typedef NS_ENUM(NSInteger, UIViewContentMode) {
    UIViewContentModeScaleToFill,
    UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
    UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.
    UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)
    UIViewContentModeCenter,              // contents remain same size. positioned adjusted.
    UIViewContentModeTop,
    UIViewContentModeBottom,
    UIViewContentModeLeft,
    UIViewContentModeRight,
    UIViewContentModeTopLeft,
    UIViewContentModeTopRight,
    UIViewContentModeBottomLeft,
    UIViewContentModeBottomRight,
};

局部拉伸:

局部拉伸有几种方法,一种是对图片本身去做拉伸,另一种是对Layer层去做拉伸;(可能还有其他的,目前只考虑这两种)

UIImage的拉伸方法:

/**
capInsets:拉伸的范围
resizingMode:拉伸的模式 常用 UIImageResizingModeStretch
*/
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); 
// the interior is resized according to the resizingMode

CALayer的拉伸方法:
通过设置CALayer的属性contentsCenter来指定拉伸区域;contentsCenter是CGRect类型,默认值为(0,0,1,1);

/**
拉伸范围
*/
@property CGRect contentsCenter;

注意CALayer的contentsRect属性的单位是比例(而不是绝对坐标)。

相关文章

  • 基础(一):UIImage图片拉伸技巧

    一、图片裁剪和拉伸 iOS中提供很好用的API帮我们实现上述功能。到iOS 6.0为止,iOS提供了3种图片拉伸的...

  • iOS 自定义下拉刷新控件 —— 解决图片拉伸与数据刷新冲突

    iOS 自定义下拉刷新控件 —— 解决图片拉伸与数据刷新冲突 iOS 自定义下拉刷新控件 —— 解决图片拉伸与数据...

  • iOS 图片拉伸

    工作中会遇到一些图片的拉伸处理,这里做一下小结 1.自定义拉伸范围处理 2.使图片两边不拉伸,中间拉伸 UIIma...

  • ios 图片拉伸

    效果: 这里是另一个人对拉伸方法的一种解析,不懂的可以看下,虽然效果一样,但我对其理解并不认同,很多方法直接查看A...

  • iOS 图片拉伸

    参考链接 在iOS6.0中,UIImage提供了一个方法处理图片拉伸 方法解释: 参数: resizingMode...

  • iOS 拉伸图片

    在一些情况下用图片来做背景,但是给的图片的尺寸很小,不能铺满给定的ImageView或者button,这时候就要靠...

  • iOS 拉伸图片

    在开发过程中总会遇到背景图片和控件大小一致的困扰,通常就是两种方法:1、找美工切大小合适的图片2、通过使用代码处理...

  • iOS 图片拉伸

    废话不多说,直接上代码 -- //保护左右侧,中间1像素进行mode UIImage * imageProtect...

  • iOS 图片拉伸

    转http://blog.csdn.net/q199109106q/article/details/8615661...

  • iOS 图片拉伸

    UIImageView * imageView = [[UIImageView alloc]initWithFra...

网友评论

      本文标题:iOS图片拉伸

      本文链接:https://www.haomeiwen.com/subject/mqovyltx.html