[英]Stretchable Images
在引用中: iPhone StretchableImageWithLeftCapWidth僅使“ D”
我有一個13x30
大小的按鈕的圖像。 我想拉伸圖像以填充尺寸為45x30
的按鈕。
這是我正在使用的代碼:
UIImage *shareImage = [[UIImage imageNamed:@"btn_red"] stretchableImageWithLeftCapWidth:16.0f topCapHeight:0.0];
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46.0f, 30.0f)];
etc....
我得到的圖像相當差。 我得到的是真實尺寸的圖像,其后有一些較淺的陰影,如圖所示 。
為什么會這樣呢? 我一點都不明白 我有正確的可擴展邏輯,並且遵循了每個人在教程/帖子中所說的話。
如果我得到一些幫助,我將不勝感激。
我認為您的左帽寬度不正確? 如果您的第一張圖像只有13像素寬,那么左上限是16呢?
左蓋是原始圖像上未拉伸的寬度
為了跟進保羅的回答,
您需要確保留出一些空間進行拉伸,因此請使用Photoshop或類似工具進行放大,並確定絕對需要哪些剩余像素。
看到這個: http : //idevrecipes.com/2010/12/08/stretchable-images-and-buttons/
LeftCapWidth應該為6.5;
UIImage *shareImage = [[UIImage imageNamed:@"btn_red"] stretchableImageWithLeftCapWidth:6.5 topCapHeight:0.0];
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46.0f, 30.0f)];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.