ios中圖片展開的幾種方式

來源:互聯網
上載者:User

標籤:

1. UIImageView整體展開

UIImageView-contentMode

typedef NS_ENUM(NSInteger, UIViewContentMode) {    UIViewContentModeScaleToFill,         // 預設 展開(會變形)    UIViewContentModeScaleAspectFit,      // 等比例展開    UIViewContentModeScaleAspectFill,     // 等比例填充    UIViewContentModeRedraw,              // redraw on bounds change (這個不清楚)     UIViewContentModeCenter,              // 下面的就是不展開按位置顯示了    UIViewContentModeTop,    UIViewContentModeBottom,    UIViewContentModeLeft,    UIViewContentModeRight,    UIViewContentModeTopLeft,    UIViewContentModeTopRight,    UIViewContentModeBottomLeft,    UIViewContentModeBottomRight,};

demo:https://github.com/vitoziv/VICMAImageView 

2. UIImage局部展開

// 按4邊間距顯示不展開的地區- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(5_0); // 按2點展開- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode;// 展開模式typedef NS_ENUM(NSInteger, UIImageResizingMode) {    UIImageResizingModeTile,//進列區域複製模式展開    UIImageResizingModeStretch,//進行漸層複製模式展開};

3.UIImage修改大小

//內縮放,一條變等於最長邊,另外一條小於等於最長邊- (UIImage *)scaleToSize:(CGSize)newSize {    CGFloat width = self.size.width;    CGFloat height= self.size.height;    CGFloat newSizeWidth = newSize.width;    CGFloat newSizeHeight= newSize.height;    if (width <= newSizeWidth &&        height <= newSizeHeight) {        return self;    }        if (width == 0 || height == 0 || newSizeHeight == 0 || newSizeWidth == 0) {        return nil;    }    CGSize size;    if (width / height > newSizeWidth / newSizeHeight) {        size = CGSizeMake(newSizeWidth, newSizeWidth * height / width);    } else {        size = CGSizeMake(newSizeHeight * width / height, newSizeHeight);    }    return [self drawImageWithSize:size];}- (UIImage *)drawImageWithSize: (CGSize)size {    CGSize drawSize = CGSizeMake(floor(size.width), floor(size.height));    UIGraphicsBeginImageContext(drawSize);        [self drawInRect:CGRectMake(0, 0, drawSize.width, drawSize.height)];    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return newImage;}


ios中圖片展開的幾種方式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.