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
  • 相关阅读:
    java的多线程学习,第二记
    java多线程的学习
    长城
    2018-12-6
    mysql的笔记
    springboot用jpa生成表,没有外键
    idea 使用方法
    Oracle数据库中文乱码问题
    JAVA-Could not create the Java virtual machine java启动失败
    log4j日志如何在ssh中配置?
  • 原文地址:https://www.cnblogs.com/laugh/p/6507030.html
Copyright © 2011-2022 走看看