iOS随笔小记

iOS随笔小记--工厂类

2017-06-23  本文已影响10人  七一小月
@interface YDFactory : NSObject
创建应用返回的BBI
/**
@param target事件的目标对象
*/ 
+(UIBarButtonItem *)CreateBackBBIWithTarget:(id)target action:(SEL)action;
创建左边带图片的BBI
/**
 @param target事件的目标对象
 */
+(UIBarButtonItem *)CreateBackBBIWithImage:(UIImage *)leftImage andHighlighted:(UIImage *)HighlightedImage andTarget:(id)target action:(SEL)action;
创建右边带图片的BBI
/**
@param target事件的目标对象
*/
+(UIBarButtonItem *)CreateRightImageBBIwithFrame:(CGRect)frame andImage:(UIImage *)titleImage andHighlighted:(UIImage *)HighlightedImage target:(id)target action:(SEL)action;
创建右边带标题的BBI
/**
@param target事件的目标对象
*/
+(UIBarButtonItem *)CreateRightTitleBBI:(NSString *)title target:(id)target action:(SEL)action;
创建中间带标题的视图
/**
@title视图名称
*/
+(UIView *)CreateCenterTitleBBI:(NSString *)title;
创建中间带图片的视图
/**
@titleImage视图图片
*/
+(UIView *)CreateCenterWithFrame:(CGRect)frame andImageBBI:(UIImage *)titleImage target:(id)target action:(SEL)action;
创建中间带图片且可编辑的视图
/**
 @titleImage视图图片
 @title 编辑提示语
*/
+(UIView *)CreateCenterImageBBI:(UIImage *)titleImage;
创建右边带图片的多个BBI
/**
@param target事件的目标对象
*/
+(UIBarButtonItem *)CreateRightSomeOneImageBBIwithFrame:(CGRect)frame andImage:(UIImage *)titleImage andHighlighted:(UIImage *)HighlightedImage andSelectedImage:(UIImage *)SelectedImage  target:(id)target action:(SEL)action andTag:(NSInteger)tag;
@implementation YDFactory
//创建应用返回的BBI
//@param target事件的目标对象
+(UIBarButtonItem *)CreateBackBBIWithTarget:(id)target action:(SEL)action{

UIView * bgView;
UIImageView * backImageView ;
if ([YDJudgeDevice JudgeDeviceVersion] == UnknownDevice){
    
    //创建一个容器来承载返回的图片和分割线
    bgView = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,44)];
    //返回图片
    backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(17, 13,10,18)];

}else{
    
    //创建一个容器来承载返回的图片和分割线
    bgView = [[UIView alloc] initWithFrame:CGRectMake(0,0,YDScreenW/7.5,YDScreenW/8.52)];
    //返回图片
    backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(YDScreenW/21.428, YDScreenW/28.846, YDScreenW/37.5,YDScreenW/20.83)];
}

backImageView.image = [UIImage imageNamed:@"goBack"];
[bgView addSubview:backImageView];
//    bgView.backgroundColor = [UIColor blueColor];
//添加手势
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[bgView addGestureRecognizer:tap];

UIBarButtonItem * backBBI = [[UIBarButtonItem alloc] initWithCustomView:bgView];

return backBBI;

  }
/**
创建左边带图片的BBI
@param target事件的目标对象
*/
+(UIBarButtonItem *)CreateBackBBIWithImage:(UIImage *)leftImage andHighlighted:(UIImage *)HighlightedImage andTarget:(id)target action:(SEL)action{

UIView * bgView;
//创建一个容器来承载返回的图片和分割线
bgView = [[UIView alloc] initWithFrame:CGRectMake(0,0,36,36) ];
//    bgView.backgroundColor = [UIColor redColor];

//返回图片
UIButton * backButton = [UIButton buttonWithType:UIButtonTypeSystem];
backButton.frame = CGRectMake(0,12,10,15);
[backButton setBackgroundImage:leftImage forState:UIControlStateNormal];
[backButton setBackgroundImage:HighlightedImage forState:UIControlStateHighlighted];
[bgView addSubview:backButton];
backButton.adjustsImageWhenHighlighted = NO;
 //添加手势
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[bgView addGestureRecognizer:tap];
[backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem * backBBI = [[UIBarButtonItem alloc] initWithCustomView:bgView];

return backBBI;
 }
//创建右边位置只带图片的BBI
+(UIBarButtonItem *)CreateRightImageBBIwithFrame:(CGRect)frame andImage:(UIImage *)titleImage andHighlighted:(UIImage *)HighlightedImage target:(id)target action:(SEL)action{

//返回图片
UIButton * backButton = [UIButton buttonWithType:UIButtonTypeSystem];
backButton.frame =  frame;
backButton.adjustsImageWhenHighlighted = NO;
[backButton setBackgroundImage:titleImage forState:UIControlStateNormal];
[backButton setBackgroundImage:HighlightedImage forState:UIControlStateHighlighted];
[backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem * bbi = [[UIBarButtonItem alloc] initWithCustomView:backButton];
return bbi;
}
/**
创建右边带标题的BBI
@param target事件的目标对象
*/
+(UIBarButtonItem *)CreateRightTitleBBI:(NSString *)title target:(id)target action:(SEL)action{

UIView * ContentView;
if ([YDJudgeDevice JudgeDeviceVersion] == UnknownDevice){
    
    //设置承载图片和标题的容器
    ContentView = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,44)];

}else{
    
    ContentView = [[UIView alloc] initWithFrame:CGRectMake(0,0,YDScreenW/7.5,YDScreenW/8.52)];
}
//设置标题
UILabel * titleLabel = [[UILabel alloc] initWithFrame:ContentView.frame];
titleLabel.text = title;
//    titleLabel.textColor = SYSTEMCOLOR;
titleLabel.font = [YDJudgeDevice shareInstance].titleFont;
titleLabel.textAlignment = NSTextAlignmentCenter;
[ContentView addSubview:titleLabel];

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[ContentView addGestureRecognizer:tap];

UIBarButtonItem * bbi = [[UIBarButtonItem alloc] initWithCustomView:ContentView];
//    ContentView.backgroundColor = [UIColor greenColor];
return bbi;
}
/**
创建中间带标题的视图
@title视图名称
*/
+(UIView *)CreateCenterTitleBBI:(NSString *)title{

UIView * titleBack ;
UILabel * titleLabel ;
titleBack = [[UIView alloc] initWithFrame:CGRectMake((1024 - 150)*0.5, 0, 150,20)];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, titleBack.frame.size.width, 20)];
//        titleBack.backgroundColor = [UIColor redColor];
titleLabel.text = title;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.font = [YDJudgeDevice shareInstance].titleFont;
titleLabel.textAlignment = NSTextAlignmentCenter;
[titleBack addSubview:titleLabel];

return titleBack;
}
/**
创建中间带图片的视图
@titleImage视图图片
*/
+(UIView *)CreateCenterWithFrame:(CGRect)frame andImageBBI:(UIImage *)titleImage target:(id)target action:(SEL)action{

//设置承载图片和标题的容器
UIView * ContentView = [[UIView alloc] initWithFrame:frame];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:ContentView.frame];
imageView.image = titleImage;
//    imageView.contentMode = UIViewContentModeScaleAspectFit;
[ContentView addSubview:imageView];

UILabel * searchLabel = [[UILabel alloc] initWithFrame:CGRectMake(frame.origin.x + YDScreenW/10, 0, CGRectGetWidth(ContentView.frame) - YDScreenW/10, CGRectGetHeight(ContentView.frame))];
searchLabel.text = @"请输入商品名称";
searchLabel.font = [YDJudgeDevice shareInstance].subTitleFont;
//    searchLabel.textColor = SUBTITLECOLOR;
[ContentView addSubview:searchLabel];

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[ContentView addGestureRecognizer:tap];

return ContentView;
 }
/**
创建中间带图片且可编辑的视图
@titleImage视图图片
*/
+(UIView *)CreateCenterImageBBI:(UIImage *)titleImage{

UIView * ContentView ;
if ([YDJudgeDevice JudgeDeviceVersion] == UnknownDevice){
    
    //设置承载图片和标题的容器
    ContentView = [[UIView alloc] initWithFrame:CGRectMake(-5,0,270,30)];

}else{
    
    ContentView = [[UIView alloc] initWithFrame:CGRectMake(-YDScreenW/75,0,YDScreenW/1.386,YDScreenW/12.3)];
}
UIImageView * imageView = [[UIImageView alloc] initWithFrame:ContentView.frame];
imageView.image = titleImage;
imageView.contentMode = UIViewContentModeScaleAspectFit;
[ContentView addSubview:imageView];

return ContentView;
}
/**
创建右边带图片的多个BBI
@param target事件的目标对象
*/
+(UIBarButtonItem *)CreateRightSomeOneImageBBIwithFrame:(CGRect)frame andImage:(UIImage *)titleImage andHighlighted:(UIImage *)HighlightedImage andSelectedImage:(UIImage *)SelectedImage  target:(id)target action:(SEL)action andTag:(NSInteger)tag{

UIView * bgView;
//创建一个容器来承载返回的图片和分割线
bgView = [[UIView alloc] initWithFrame:frame];

//返回图片
UIButton * backButton = [UIButton buttonWithType:UIButtonTypeSystem];
backButton.frame =  CGRectMake(0, 10, 25, 25);
backButton.adjustsImageWhenHighlighted = NO;
backButton.tag = tag;
[backButton setBackgroundImage:titleImage forState:UIControlStateNormal];
[backButton setBackgroundImage:HighlightedImage forState:UIControlStateHighlighted];
[backButton setBackgroundImage:SelectedImage forState:UIControlStateSelected];
[bgView addSubview:backButton];

//添加手势
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[bgView addGestureRecognizer:tap];
[backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem * backBBI = [[UIBarButtonItem alloc] initWithCustomView:bgView];


return backBBI;
}
上一篇下一篇

猜你喜欢

热点阅读