您的位置:首页 > 产品设计 > UI/UE

UIImageView如何以九宫格方式拉伸一个图片

2012-03-04 21:24 1061 查看

                                      UIImageView如何以九宫格方式拉伸一个图片

        首先要创建一个普通的UIImage,然后用UIImage的 stretchbleImageWithLeftCapWidth:  topCapHeight方法,指定左右两边保持不拉伸的范围,和上下两边保持不拉伸的范围,创建出一个新的UIImage.

       然后将这个UIImage设置到需要的UIImageView中。

      最后,设置UIImageView的frame,这样UIImageView就会自己根据frame的大小去保持四个角不拉伸的方式去拉伸图片啦。

UIImage *contentBgImagebubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fromSelf?@"bubbleSelf":@"bubble" ofType:@"png"]];

UIImage * newBgImage =[contentBgImagebubble stretchableImageWithLeftCapWidth:21 topCapHeight:14] ;

UIImageView * contentBgImage=[[UIImageView alloc] initWithImage:newBgImage];

contentBgImage.frame=CGRectMake(10,10,200,100);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐