- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapWidth;
Creates and returns a new image object with the specified cap values.
During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the 1-pixel wide area not covered by the cap in each direction is what is scaled or resized. This technique is often used to create variable-width buttons, which retain the same rounded corners but whose center region grows or shrinks as needed.
上面是官方文檔上得解釋许起。意思就是用來創(chuàng)建一個(gè)內(nèi)容可拉伸勘畔,而邊角不拉伸的圖片,需要兩個(gè)參數(shù)唱逢,第一個(gè)是左邊不拉伸區(qū)域的寬度渡八,第二個(gè)參數(shù)是上面不拉伸的高度迂求。那么接下來的一個(gè)像素會(huì)被拉伸。例如欢嘿,leftCapHeight為6衰琐,topCapHeight為8也糊。那么,圖片左邊的6個(gè)像素羡宙,上邊的8個(gè)像素狸剃。不會(huì)被拉伸,而左邊的第7個(gè)像素狗热,上邊的第9個(gè)像素這一塊區(qū)域?qū)?huì)被拉伸钞馁。剩余的部分也不會(huì)被拉伸。