拉伸圖片spa
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
[image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5]
剪切圖片code
設置UIImageView的contentMode圖片
// 設置左邊顯示一個放大鏡,圖片的尺寸是15*15 UIImageView *leftView = [[UIImageView alloc] init]; leftView.image = [UIImage imageWithName:@"searchbar_textfield_search_icon"]; leftView.width = leftView.image.size.width + 10; leftView.height = leftView.image.size.height; // 設置leftView的內容居中 leftView.contentMode = UIViewContentModeCenter;
UIViewContentMode的內容
ip
typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped. UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay) UIViewContentModeCenter, // contents remain same size. positioned adjusted. UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, };