stretchableImageWithLeftCapWidth用法

stretchableImageWithLeftCapWidth通常用來(lái)做圖片的局部拉伸,常用的例子是聊天的背景圖的部分拉伸

stretchableImageWithLeftCapWidth這個(gè)方法 有2個(gè)參數(shù)
leftCapWidth: 左邊不拉伸的像素
topCapHeight:上邊不拉伸的像素

例如如下的點(diǎn):

則取橫坐標(biāo)軸26的像素點(diǎn)橫向拉伸到一定寬度
取縱坐標(biāo)軸11的像素點(diǎn)縱向拉伸到一定長(zhǎng)度 (具體長(zhǎng)度又imageview的frame決定)
image = [image stretchableImageWithLeftCapWidth:25 topCapHeight:10];

    UIImage *image = [UIImage imageNamed:@"ic_nav_back_dark"];
    UIImageView *view = [[UIImageView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    view.image = image;
    
    view.frame = CGRectMake(60, 60, 100, 100);
    
    [self.view addSubview:view];
    
    
    UIImageView *view1 = [[UIImageView alloc] init];
    view1.backgroundColor = [UIColor whiteColor];
    image = [image stretchableImageWithLeftCapWidth:25 topCapHeight:10];
    view1.image = image;
    
    view1.frame = CGRectMake(60, 300, 100, 100);
    
    [self.view addSubview:view1];
    
    UIImageView *view2 = [[UIImageView alloc] init];
    view2.backgroundColor = [UIColor whiteColor];
    UIImage *image1 = [UIImage imageNamed:@"ic_nav_back_dark"];
    image1 = [image1 stretchableImageWithLeftCapWidth:1 topCapHeight:1];
    view2.image = image1;
    view2.frame = CGRectMake(200, 300, 100, 100);
    [self.view addSubview:view2];

效果如下:

855CAC19-ED4F-494C-BD32-21D00213D10A.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容