图片拉伸方法

因为要兼容5.0所以还是用了    stretchableImageWithLeftCapWidthtopCapHeight:的方法


//图片拉伸

    UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, 200.0, 28.0)];

    imageview1.image = [UIImage imageNamed:@"1@2x"];

    [self.view addSubview:imageview1];

    

    UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 65.0, 300.0, 28.0)];

    imageview2.image = [[UIImage imageNamed:@"1"] stretchableImageWithLeftCapWidth:60.0 topCapHeight:10.0];

//    imageview.image = [[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1@2x" ofType:@"png"]]] stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];

    [self.view addSubview:imageview2];

    

    UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100.0, 300.0, 28.0)];

    imageview3.image = [[UIImage imageNamed:@"1"] stretchableImageWithLeftCapWidth:5.0 topCapHeight:10.0];

    [self.view addSubview:imageview3];

    

    UIImageView *imageview4 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 135.0, 300.0, 56.0)];

    imageview4.image = [[UIImage imageNamed:@"1"] stretchableImageWithLeftCapWidth:5.0 topCapHeight:5.0];

    [self.view addSubview:imageview4];




使用的是@2x的图片,在使用stretchableImageWithLeftCapWidth:   topCapHeight:方法时不能加载@2x的图片,不然拉伸效果不对。所以使用imageWithData加载@2x图片的拉伸也是不对。


上面测试了三种拉伸效果,从图片的拉伸效果看其实拉伸的时候从我们设置的LeftCapWidth:开始拉伸。我看人家介绍拉伸的像素点是LeftCapWidth:和topCapHeight:的一个像素点的。但是测试看的如果是长度拉伸的话应该LeftCapWidth:开始的一条像素的拉伸。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值