Latest 0.1.0
License MIT
Platforms ios 8.0, requires ARC


deal ninePoints






本方法主要结合系统方法和一些自己的处理,使之适应各种情况下的点9图片拉伸变化(包括多方向多点和有无内容填充区的支持)。并在testResources文件夹下放了一些图片,方便大家测试 ,只需要修改MainViewController中传递的参数即可



-(UIImage )drawNinePatchImage:(UIImage )image stretchingSize:(CGSize)stretchingSize;

//image 传入点9图片
//textFont 为文本字体大小
-(UIImage )drawNinePatchImage:(UIImage )image contentText:(NSString )contentText textFont:(UIFont )font viewMaxSize:(CGSize)viewMaxSize;

//作为内容填充者,还有两种需求,1.做内容背景的时候,直接设置最大输入内容区域背景 ,这个在NinePointsViewController提供了inputContentToDisplayTheMaximumBackgroundImage这个事例方法给大家看看

  1. In fact, there are several demo of the change of support point 9 on the Internet,
    but it is either very old or not satisfying the requirements.
  2. As an android student. The point 9 is shown on the left side,
    which may have multiple points, and the length of each point is stretched according to the length of the black side
  3. The black edge requirement on the right and bottom of the point 9 graph can only be one,
    which means that the content fills the area. After the content exceeds this area, the image will be stretched

This method mainly combines the system method and some of its own processing to make it adapt to the changes of the point 9 images in various situations (including the support of multi-direction and the presence of content filling areas). And I’ve put some images in the testResources folder so that you can test them and just modify the parameters passed in the mainview controller

The following three usage methods are provided externally:

// incoming point 9 image. StretchingSize is the width that needs to be stretched,
This is generally used for simple picture stretching

  • (UIImage ) drawNinePatchImage: UIImage ) image stretchingSize (CGSize) stretchingSize;

//image incoming point 9 image
//contenttext is the display text,
//textFont size is text font size
//viewMaxSize is the maximum width shown, the default preferred stretch width, the width reaches the maximum tensile height, and the height reaches the maximum when it is not stretched
// this is generally used as a fixed text, and then input background, such as bubbles and text in chat records
(UI image )image contentText:(NSString ) content_viewmaxsize (CGSize)viewMaxSize;

/ / as a filler content, there are two kinds of demand, 1. The content background set maximum input content area directly, this in NinePointsViewController provides inputContentToDisplayTheMaximumBackgroundImage this case method for everyone to see

  1. When entering background, change the background size according to the input content. This provides inputContentToDisplayTheChangeBackgroundImage in NinePointsViewController
    Let me give you an example. The basic principle is to put an image after the input area, and then change the text content according to the change of content. Provides a GIF rendering


if find some question or other suggest please tell me QQ:[email protected]

Latest podspec

    "name": "MJNinePatch",
    "version": "0.1.0",
    "summary": "nine patch",
    "description": "nine patch....",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "majian": "[email protected]"
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "0.1.0"
    "source_files": "NinePointsImageDemo/NinePointsImageDemo/NinePatch/**/*.{h,m}",
    "requires_arc": true

Pin It on Pinterest

Share This