zoukankan      html  css  js  c++  java
  • 按钮背景图片拉伸

        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(50, 50, 200, 200);
       // imageView.image = [UIImage imageNamed:@"chat_send_nor"];
        
        [self.view addSubview:imageView];
        
        
        UIImage *image = [UIImage  imageNamed:@"chat_send_nor"];
    //    image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30,30, 30,30) resizingMode:UIImageResizingModeStretch];
        
        image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height *0.5];
        
        imageView.image = image;
        
        

     UIimage扩展

    #import <UIKit/UIKit.h>
    
    @interface UIImage (Extension)
    +(UIImage *)resiableImage:(NSString *)name;
    @end
    #import "UIImage+Extension.h"
    
    @implementation UIImage (Extension)
    
    +(UIImage *)resiableImage:(NSString *)name
    {
        UIImage *image = [self imageNamed:name];
        
        return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height *0.5];
    
    
    }
    
    
    
    @end

    扩展方法点使用

    //
    //  ViewController.m
    //  图片拉伸
    #import "ViewController.h"
    #import "UIImage+Extension.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(50, 50, 200, 200);
        imageView.image = [UIImage resiableImage:@"chat_send_nor"];
        
        [self.view addSubview:imageView];
        
    //    
    //    UIImage *image = [UIImage  imageNamed:@"chat_send_nor"];
    ////    image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30,30, 30,30) resizingMode:UIImageResizingModeStretch];
    //    
    //    //image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height *0.5];
    //    
    //    imageView.image = image;
    //    
        
        
    }
    
    
    @end
    本人无商业用途,仅仅是学习做个笔记,特别鸣谢小马哥,学习了IOS,另日语学习内容有需要文本和音频请关注公众号:riyuxuexishuji
  • 相关阅读:
    rosservice call ERROR:Unable to load type ... Have you typed 'make'
    查看ubuntu版本号
    VirtualBox虚拟机 host/guest 拷贝粘贴,共享剪贴板,安装guest additions
    traffic_light_bag_file 数据集 下载链接
    ubuntu linux double tab
    ubuntu linux查看cpu信息
    ubuntu linux查看硬盘使用量
    ubuntu查看nvidia显卡状态
    ibus
    windows7 屏幕亮图胡乱变化
  • 原文地址:https://www.cnblogs.com/laugh/p/6507030.html
Copyright © 2011-2022 走看看