我們?cè)趯?dǎo)航欄或標(biāo)簽欄上設(shè)置背景圖片時(shí)會(huì)遇到圖片的尺寸不夠大,在這里介紹幾個(gè)關(guān)于圖片拉伸問題的解決辦法
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width-20)/2, 5, 20, 20)];
//原圖顯示,解決圖片拉伸問題
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.image = [UIImage imageNamed:@"123"];
UIImage *image = [[ThemeManager shareThemeManager] getThemeImageWithImageName:@"123.png"];
CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, CGRectMake(10, 0, kScreenWidth, 64));
UIImage *endImage = [UIImage imageWithCGImage:imageRef];
這里要注意的是出發(fā)點(diǎn)坐標(biāo)如果設(shè)置成(0,0),那末左上角有1點(diǎn)點(diǎn)邊角效果,這樣就不好看了,所以1般起始點(diǎn)坐標(biāo)x1般設(shè)置>0,假設(shè)設(shè)置成10,意思就是圖片向右側(cè)裁剪掉了10個(gè)像素點(diǎn)后的位置放在了(0,0)處,這樣就解決了邊角問題
解決前:
解決后: