图片拉伸不变形

来源:互联网 发布:mac sublime 菜单栏 编辑:程序博客网 时间:2024/05/16 02:01

    //拉伸后

    UIImage *image = [UIImageimageNamed:@"mall_icon_y"];

    UIEdgeInsets insets =UIEdgeInsetsMake(10,10,10,10);

    // 指定为拉伸模式,伸缩后重新赋值

    image = [image resizableImageWithCapInsets:insetsresizingMode:UIImageResizingModeStretch];

    

    UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeSystem];

    [btn setBackgroundImage:imageforState:UIControlStateNormal];

    btn.frame =CGRectMake(10,60,50,30);

    [self.viewaddSubview:btn];

    

    //原始大小

    UIImage *image1 = [UIImageimageNamed:@"mall_icon_y"];

    UIButton *btn1 = [UIButtonbuttonWithType:UIButtonTypeSystem];

    [btn1 setBackgroundImage:image1forState:UIControlStateNormal];

    btn1.frame =CGRectMake(10,100,108,30);

    [self.viewaddSubview:btn1];

0 0
原创粉丝点击