zoukankan      html  css  js  c++  java
  • image图片拉伸

    //iOS5以前设置拉伸图片

    -(void)loadImageBeforeIOS5{

        //35*30

        UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(80, 180, 100, 40)];

        [nextButton setTitle:@"iOS5之前" forState:UIControlStateNormal];

        nextButton.layer.borderColor=[[UIColor redColor] CGColor];

        nextButton.layer.borderWidth=1.0f;

        UIImage *image = [UIImage imageNamed:@"Question"];

        // 设置左边端盖宽度  rightCap=width - leftCapWidth - 1

        NSInteger leftCapWidth = image.size.width * 0.5;

        // 设置上边端盖高度  bottom=height - topCapWidth - 1

        NSInteger topCapHeight = image.size.height * 0.5;

        UIImage *newImage = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];

        [nextButton setBackgroundImage:newImage forState:UIControlStateNormal];

        [self.view addSubview:nextButton];

    }

    //iOS5 拉伸图片

    -(void)loadImageIOS5{

         UIImage *image = [UIImage imageNamed:@"Question"];

        UIButton  *resizableButton=[[UIButton alloc]initWithFrame:CGRectMake(80, 250, 100, 40)];

        [resizableButton setTitle:@"iOS5" forState:UIControlStateNormal];

        // 设置端盖的值

        CGFloat top = image.size.height * 0.5;

        CGFloat left = image.size.width * 0.5;

        CGFloat bottom = image.size.height * 0.5;

        CGFloat right = image.size.width * 0.5;

        

        UIEdgeInsets edgeInsets = UIEdgeInsetsMake(top, left, bottom, right);

        

        // 拉伸图片

        UIImage *edgeImage = [image resizableImageWithCapInsets:edgeInsets];

        

        // 设置按钮的背景图片

        [resizableButton setBackgroundImage:edgeImage forState:UIControlStateNormal];

        [self.view addSubview:resizableButton];

    }

    //iOS6 拉伸图片

    -(void)loadImageAfterIOS6{

        UIImage *image = [UIImage imageNamed:@"Question"];

        UIButton  *resizableButtonMode=[[UIButton alloc]initWithFrame:CGRectMake(80, 320, 180, 400)];

        [resizableButtonMode setTitle:@"iOS6" forState:UIControlStateNormal];

        [resizableButtonMode addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

        // 设置上左下右边距

        CGFloat topMode= image.size.height * 0.5;

        CGFloat leftMode= image.size.width * 0.5;

        CGFloat bottomMode= image.size.height * 0.5;

        CGFloat rightMode= image.size.width * 0.5;

        

        UIEdgeInsets edgeInsetsMode= UIEdgeInsetsMake(topMode, leftMode, bottomMode, rightMode);

        

        // 拉伸图片

        UIImage *edgeModeImage = [image resizableImageWithCapInsets:edgeInsetsMode resizingMode:UIImageResizingModeStretch];

    //    UIImage *edgeModeImage = [image resizableImageWithCapInsets:edgeInsetsMode resizingMode:UIImageResizingModeTile];

        

        //设置图片

        [resizableButtonMode setBackgroundImage:edgeModeImage forState:UIControlStateNormal];

        [self.view addSubview:resizableButtonMode];

    }

  • 相关阅读:
    bzoj1854 [Scoi2010]游戏
    bzoj2456 mode
    bzoj4810 [Ynoi2017]由乃的玉米田
    bzoj1076 [SCOI2008]奖励关
    bzoj3064 Tyvj 1518 CPU监控
    bzoj1798 [Ahoi2009]维护序列
    bzoj3575 [Hnoi2014]道路堵塞
    bzoj3992 [SDOI2015]序列统计
    uoj#34. 多项式乘法
    高等代数典型问题集
  • 原文地址:https://www.cnblogs.com/daxueshan/p/6269181.html
Copyright © 2011-2022 走看看