UIButton图片拉伸

来源:互联网 发布:java数据结构视频教程 编辑:程序博客网 时间:2024/05/19 11:45
在UIButton中加入一个UIImageView,拉伸imageView的UIimage,然后将button的背景设为clearColor等等。把imageView放入button中,

//刚才image拉伸的代码 

//图片处理

    CGFloat top = floorf(image.size.height/2);// 顶端盖高度

    CGFloat bottom = image.size.height-(image.topCapHeight+1) ;// 底端盖高度

    CGFloat left = floorf(image.size.width/2);// 左端盖宽度

    CGFloat right = image.size.width - (image.leftCapWidth +1); // 右端盖宽度

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

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

    image = [image resizableImageWithCapInsets:insetsresizingMode:UIImageResizingModeStretch];

这是本人试出来的方法,也是唯一适合Button的方法,如果有更好的,欢迎大家提供下


0 0
原创粉丝点击