iOS 图片点九拉伸效果

Github Demo:
https://github.com/KenLuChinese/NinePointImage#ninepointimage

icon

    UIImageView *imageView = [[UIImageView alloc] init];
    
    UIImage *pointImage = [UIImage imageNamed:@"nine_point"];
    CGFloat imageWidth  = pointImage.size.width;
    CGFloat imageHeight = pointImage.size.height;

    /// 四个内边距合成中间的方形,方形区域向四方拉伸
    UIEdgeInsets insets = UIEdgeInsetsMake(imageHeight*0.5, imageWidth*0.5, imageHeight*0.5-1, imageWidth*0.5-1);
    /// 主要方法
    pointImage = [pointImage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    
    imageView.image = self.pointImage;

效果图

① 是没有拉伸的效果
② 是拉伸以后的效果

你可能感兴趣的:(iOS 图片点九拉伸效果)