接上篇:
3.
+ (UIImage *)inputBar
{
if ([JSMessageInputView inputBarStyle] == JSInputBarStyleFlat)
return [UIImage imageNamed:@"input-bar-flat"];
else
return [[UIImage imageNamed:@"input-bar"] resizableImageWithCapInsets:UIEdgeInsetsMake(19.0f, 3.0f, 19.0f, 3.0f)];
}
self.image = [UIImage inputBar];
效果是返回一个有背景的UIImageView,这里的作用就是提供一个附加功能的Category(原理也是封装!)。
有无实现的区别如下:
自己稍微测试了一下,效果非常好
Category 部分:
#import "UIImage+BackgroundSet.h"
@implementation UIImage (BackgroundSet)
+ (UIImage*)backgroundSet
{
return [[UIImage imageNamed:@"input-bar-flat"] resizableImageWithCapInsets:UIEdgeInsetsMake(19.0f, 3.0f, 19.0f, 3.0f)];
}
@end
视图控制器展示部分:
#import "UIImage+BackgroundSet.h"
#import "LBCategoryTestController.h"
@interface LBCategoryTestController ()
@property (nonatomic, strong) UIImageView* imageView;
@end
@implementation LBCategoryTestController
- (void)viewDidLoad
{
[super viewDidLoad];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width, 80)];
[_imageView setBackgroundColor:[UIColor yellowColor]];
[_imageView setImage:[UIImage backgroundSet]];
[self.view addSubview:_imageView];
}
@end
效果对比:
这个是用来拉伸的图片: