iOS圖片拉伸三種方式

###圖片拉伸 ####1.第一種圖形界面 第一步 第二步 ######第三步 圖形設置只須要點點就行,至於拉伸大小,系統已替你算好 ####2.代碼方式git

  • 第一種
    UIImageView *imageView=[[UIImageView alloc]init];
     UIImage *image=[UIImage imageNamed:@"chat_send_nor"];
     image=[image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeTile];
     imageView.image=image;
     imageView.frame=CGRectMake(30, 50, 200, 200);
     [self.view addSubview:imageView];
  • 第二種
    UIImageView *imageView=[[UIImageView alloc]init];
    UIImage *image=[UIImage imageNamed:@"chat_send_nor"];

// image=[image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeTile]; image=[image stretchableImageWithLeftCapWidth:image.size.width*0.5 topCapHeight:image.size.height]; imageView.image=image; imageView.frame=CGRectMake(30, 50, 200, 200); [self.view addSubview:imageView];github

//    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight __TVOS_PROHIBITED;
//    @property(nonatomic,readonly) NSInteger leftCapWidth __TVOS_PROHIBITED;   // default is 0. if non-zero, horiz. stretchable. right cap is calculated as width - leftCapWidth - 1
//    @property(nonatomic,readonly) NSInteger topCapHeight __TVOS_PROHIBITED;   // default is 0. if non-zero, vert. stretchable. bottom cap is calculated as height - topCapWidth - 1
//
//實際就是1,也是圖形與圖形界面同樣的結果
// right = width - left - 1;
// 1 = width - left - right;
// bottom = height - top - 1;
// 1 = height - top - bottom;
//能夠將其封裝成一個uiimage的分類,這樣能夠重用
```

####3.github地址 githubui

相關文章
相關標籤/搜索