博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS之UIButton的封装和常用属性\按钮UIButton的常用属性及方法总结(二)、多按钮排列、cell上多图片布局
阅读量:4290 次
发布时间:2019-05-27

本文共 17407 字,大约阅读时间需要 58 分钟。

-(void)addbtn{

  

//UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];

    // 设置自定义的按钮

UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeCustom];//UIButtonTypeRoundedRect是设置一个圆角按钮

// 按钮的位置坐标

    btn.frame=CGRectMake(80,250,250,30);

    

// 普通状态按钮标题

    [btn setTitle:@"Button"forState:UIControlStateNormal];

//  高亮状态的按钮标题,点击按钮时会高亮

    [btn setTitle:@"高亮状态" forState:UIControlStateHighlighted];//

    

// 高亮状态光晕效果

    [btn setShowsTouchWhenHighlighted:YES];

    

//设置标题的颜色

    [btn setTitleColor:[UIColorredColor]forState:UIControlStateNormal];

//设置高亮时的标题的颜色

    [btn setTitleColor:[UIColorgreenColor]forState:UIControlStateHighlighted];

    

// 设置标题的字体大小

    [btn.titleLabelsetFont:[UIFontboldSystemFontOfSize:20]];

    btn.titleLabel.font = [UIFontsystemFontOfSize:16];

    btn.titleLabel.font=[UIFontsystemFontOfSize:17weight:UIFontWeightBold];

    

//设置背景颜色

    [btn setBackgroundColor:[UIColorblueColor]];

    

// 图片被拉伸式地设置背景图片

    [btn setBackgroundImage:[UIImageimageNamed:@"bankYellow"]forState:UIControlStateNormal];

//  按钮被选中时的背景图片

    [btn setBackgroundImage:[UIImageimageNamed:@"bankBlue"]forState:UIControlStateHighlighted];

    

//设置按钮的图片,超过按钮尺寸会吧标题也覆盖掉

    [btn setImage:[UIImageimageNamed:@"bankYellow"]forState:UIControlStateNormal];

//设置按钮高亮时的图片,也就是按钮点击下去未松开的时候;

    [btn setImage:[UIImageimageNamed:@"bankBlue"]forState:UIControlStateHighlighted];

//设置按钮被选中时的图片,select属性必须设置为yes,选中时的图片才有作用

    btn.selected=YES;

     [btn setImage:[UIImageimageNamed:@"bankBlue"]forState:UIControlStateSelected];

    

//设置按钮内容的对其方式

btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;

 

    //添加按钮的点击事件

    [btn addTarget:self action:@selector(sendNoti:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.viewaddSubview:btn];

  

}

-(void)sendNoti:(UIButton *)sender{

    threeVC *three=[[threeVCalloc]init];

    [self.navigationControllerpushViewController:threeanimated:YES];

}

 

 

 

=====简单的封装:

 

调用:

  NSDictionary *dict=@{

         @"title":@"第一",//标题

         @"highlightTitle":@"第二",//高亮标题

         @"selectedTitle":@"第三",//选中时的标题

         

         @"titlecolor":[UIColorredColor],//标题颜色

         @"highlighttitlecolor":[UIColorgreenColor],//高亮标题颜色

         @"selectedtitlecolor":[UIColoryellowColor],//选中时标题颜色

 

//         @"image":@"bankYellow",//图片

//         @"highlightimage":@"bankBlue",//高亮图片

//         @"selectedimage":@"bankGreen",//选中时的图片

//

//         @"bgimage":@"bankYellow",//背景图片

//         @"highlightbgimage":@"bankBlue",//高亮背景图片

//         @"selectedbgimage":@"bankGreen",//选中时的背景图片

//

 

         @"bgcolor":[UIColorblueColor],//背景颜色

         @"highlightbgcolor":[UIColorgreenColor],//高亮时背景颜色

         @"selectedbgcolor":[UIColorredColor],//选中时的背景颜色

         

         @"isSetShowsTouchWhenHighlighted":[NSNumbernumberWithBool:YES],// 高亮状态是否有光晕效果,BOOl类型

         @"fontsize":[NSNumbernumberWithInteger:30],//标题大小NSInteger类型

         @"btnaligmentmark":@"",//按钮内容对齐方式的标识,1左对齐,2右对齐,3填充,其他居中NSInteger类型 ,[NSNumber numberWithInteger:1];

         @"isSelectedBtn":[NSNumbernumberWithBool:YES]

                         };

   

    LYBaseBtn *btn=[[LYBaseBtnalloc]initWithFrame:CGRectMake(0,100,100, 50withDict:dict];

    //添加按钮的点击事件

    [btn addTarget:self action:@selector(sendNoti:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:btn];

 

btn封装:

 

#import <UIKit/UIKit.h>

 

@interface LYBaseBtn : UIButton

/**

 *arr    参数数组

 */

-(instancetype)initWithFrame:(CGRect)frame withDict:(NSDictionary *)dict;

@property(nonatomic,copy)NSString *title;//标题

@property(nonatomic,copy)NSString *highlightTitle;//高亮标题

@property(nonatomic,copy)NSString *selectedTitle;//选中时的标题

 

@property(nonatomic,copy)NSString *image;//图片

@property(nonatomic,copy)NSString *highlightimage;//高亮图片

@property(nonatomic,copy)NSString *selectedimage;//选中时的图片

 

@property(nonatomic,copy)NSString *bgimage;//背景图片

@property(nonatomic,copy)NSString *highlightbgimage;//高亮背景图片

@property(nonatomic,copy)NSString *selectedbgimage;//选中时的背景图片

 

@property(nonatomic,strong)UIColor *titlecolor;//标题颜色

@property(nonatomic,strong)UIColor *highlighttitlecolor;//高亮标题颜色

@property(nonatomic,strong)UIColor *selectedtitlecolor;//选中标题颜色

 

@property(nonatomic,strong)UIColor *bgcolor;//背景颜色

@property(nonatomic,strong)UIColor *highlightbgcolor;//高亮背景颜色

@property(nonatomic,strong)UIColor *selectedbgcolor;//选中背景颜色

 

@property(nonatomic,assign)BOOL isSetShowsTouchWhenHighlighted;// 高亮状态是否有光晕效果

 

@property(nonatomic,assign)UIControlContentHorizontalAlignment btnalignment;//按钮内容个对齐方式

 

@property(nonatomic,assign)NSInteger btnaligmentmark;//对齐方式的标志

 

 

@property(nonatomic,assign)NSInteger fontsize;//字体大小

 

@property(nonatomic,assign)BOOL isSelectedBtn;//按钮是否选中

 

@end

-------

 

#import "LYBaseBtn.h"

 

@implementation LYBaseBtn

-(instancetype)initWithFrame:(CGRect)frame withDict:(NSDictionary *)dict{

    if(self==[superinitWithFrame:frame]){

       

        [selfsetAttributeWithDict:dict];//设置属性

        [self addbtn];//添加按钮

    }

    return self;

}

 

-(void)addbtn{

    if(self.title){

    // 普通状态按钮标题

    [selfsetTitle:self.titleforState:UIControlStateNormal];

    }

    if(self.highlightTitle){

    //  高亮状态的按钮标题,点击按钮时会高亮

        [selfsetTitle:self.highlightTitleforState:UIControlStateHighlighted];

    }

    if(self.selectedTitle &&self.isSelectedBtn){

        //  高亮状态的按钮标题,点击按钮时会高亮

        [selfsetTitle:self.selectedTitleforState:UIControlStateSelected];

    }

    

    if(self.isSetShowsTouchWhenHighlighted){

    // 高亮状态光晕效果

    [selfsetShowsTouchWhenHighlighted:self.isSetShowsTouchWhenHighlighted];

    }

    

    if(self.titlecolor){

    //设置标题的颜色

    [selfsetTitleColor:self.titlecolorforState:UIControlStateNormal];

    }

    if(self.highlighttitlecolor){

    //设置高亮时的标题的颜色

    [selfsetTitleColor:self.highlighttitlecolorforState:UIControlStateHighlighted];

    }

    if(self.selectedtitlecolor&&self.isSelectedBtn){

        //设置选中时的标题的颜色

        [selfsetTitleColor:self.selectedtitlecolorforState:UIControlStateSelected];

    }

    

    if(self.fontsize){

// 设置标题的字体大小

    self.titleLabel.font=[UIFontsystemFontOfSize:self.fontsizeweight:UIFontWeightBold];

    }

    

    if(self.bgcolor){

    //设置背景颜色

    [selfsetBackgroundColor:self.bgcolor];

    }

    if(self.highlightbgcolor){

        //设置高亮背景颜色

        [selfsetBackgroundColor:self.highlightbgcolor];

    }

    if(self.selectedbgcolor&&self.isSelectedBtn){

        //设置选中时的背景颜色

        [selfsetBackgroundColor:self.selectedbgcolor];

    }

    

    

    if(self.bgimage){

    // 图片被拉伸式地设置背景图片

    [selfsetBackgroundImage:[UIImageimageNamed:self.bgimage]forState:UIControlStateNormal];

    }

     if(self.highlightbgimage){

    //  按钮高亮时的背景图片

    [selfsetBackgroundImage:[UIImageimageNamed:self.highlightbgimage]forState:UIControlStateHighlighted];

     }

    if(self.selectedimage&&self.isSelectedBtn){

        //  按钮选中时的背景图片

        [selfsetBackgroundImage:[UIImageimageNamed:self.selectedimage]forState:UIControlStateSelected];

    }

    

    

    if(self.image){

    //设置按钮的图片,超过按钮尺寸会吧标题也覆盖掉

    [selfsetImage:[UIImageimageNamed:self.image]forState:UIControlStateNormal];

    }

   if(self.highlightimage){

    //设置按钮高亮时的图片,也就是按钮点击下去未松开的时候;

       [selfsetImage:[UIImageimageNamed:self.highlightimage]forState:UIControlStateHighlighted];

   }

    if(self.selectedimage&&self.isSelectedBtn){

    //设置按钮被选中时的图片,select属性必须设置为yes,选中时的图片才有作用

    self.selected=YES;

    [selfsetImage:[UIImageimageNamed:self.selectedimage]forState:UIControlStateSelected];

    }

    

    if(self.btnalignment){

    //设置按钮内容的对其方式

     self.contentHorizontalAlignment=self.btnalignment;

    }

}

 

-(void)setAttributeWithDict:(NSDictionary *)dict{

//标题

    if([[dictallKeys]containsObject:@"title"]&& ![dict[@"title"]isEqualToString:@""]){

     self.title=dict[@"title"];

    }

//高亮标题

    if([[dictallKeys]containsObject:@"highlightTitle"]&& ![dict[@"highlightTitle"]isEqualToString:@""]){

    self.highlightTitle=dict[@"highlightTitle"];

    }

//选中标题

    if([[dictallKeys]containsObject:@"selectedTitle"]&& ![dict[@"selectedTitle"]isEqualToString:@""]){

    self.selectedTitle=dict[@"selectedTitle"];

    }

    

//*********标题颜色

    if([[dictallKeys]containsObject:@"titlecolor"] && [dict[@"titlecolor"]isKindOfClass:[UIColorclass]]){

        self.titlecolor=dict[@"titlecolor"];

    }

    //高亮标题颜色

    if([[dictallKeys]containsObject:@"highlighttitlecolor"] && [dict[@"highlighttitlecolor"]isKindOfClass:[UIColorclass]]){

        self.highlighttitlecolor=dict[@"highlighttitlecolor"];

    }

    //选中标题颜色

    if([[dictallKeys]containsObject:@"selectedtitlecolor"] && [dict[@"selectedtitlecolor"]isKindOfClass:[UIColorclass]]){

        self.selectedtitlecolor=dict[@"selectedtitlecolor"];

    }

//****按钮图片

     if([[dictallKeys]containsObject:@"image"]&& ![dict[@"image"]isEqualToString:@""]){

    self.image=dict[@"image"];

     }

//按钮高亮图片

     if([[dictallKeys]containsObject:@"highlightimage"]&& ![dict[@"highlightimage"]isEqualToString:@""]){

    self.highlightimage=dict[@"highlightimage"];

     }

//按钮选中图片

    if([[dictallKeys]containsObject:@"selectedimage"]&& ![dict[@"selectedimage"]isEqualToString:@""]){

    self.selectedimage=dict[@"selectedimage"];

    }

//********背景图片

     if([[dictallKeys]containsObject:@"bgimage"]&& ![dict[@"bgimage"]isEqualToString:@""]){

    self.bgimage=dict[@"bgimage"];

     }

//高亮背景图片

    if([[dictallKeys]containsObject:@"highlightbgimage"]&& ![dict[@"highlightbgimage"]isEqualToString:@""]){

    self.highlightbgimage=dict[@"highlightbgimage"];

    }

//选中的背景图片

     if([[dictallKeys]containsObject:@"selectedbgimage"]&& ![dict[@"selectedbgimage"]isEqualToString:@""]){

    self.selectedbgimage=dict[@"selectedbgimage"];

     }

 

    

//*********背景颜色

     if([[dictallKeys]containsObject:@"bgcolor"] && [dict[@"bgcolor"]isKindOfClass:[UIColorclass]]){

    self.bgcolor=dict[@"bgcolor"];

     }

//高亮背景颜色

    if([[dictallKeys]containsObject:@"highlightbgcolor"] && [dict[@"highlightbgcolor"]isKindOfClass:[UIColorclass]]){

        self.highlightbgcolor=dict[@"highlightbgcolor"];

    }

//选中背景颜色

    if([[dictallKeys]containsObject:@"selectedbgcolor"] && [dict[@"selectedbgcolor"]isKindOfClass:[UIColorclass]]){

        self.selectedbgcolor=dict[@"selectedbgcolor"];

    }

   

//选中时是否有光晕

     if([[dictallKeys]containsObject:@"isSetShowsTouchWhenHighlighted"]&& [dict[@"isSetShowsTouchWhenHighlighted"]boolValue]!=0){

self.isSetShowsTouchWhenHighlighted=[dict[@"isSetShowsTouchWhenHighlighted"]boolValue];

     }else {

         self.isSetShowsTouchWhenHighlighted=NO;

     }

    

//标题大小

 if([[dictallKeys]containsObject:@"fontsize"]&& [dict[@"fontsize"]integerValue]!=0){

     self.fontsize=[dict[@"fontsize"]integerValue];

 }else {

     self.fontsize=17;

 }

//按钮内容对齐方式

    if([[dictallKeys]containsObject:@"btnaligmentmark"] && [dict[@"btnaligmentmark"]integerValue]){

        if([dict[@"btnaligmentmark"]integerValue] ==1){

            self.btnalignment=UIControlContentHorizontalAlignmentLeft;

        }else if([dict[@"btnaligmentmark"]integerValue] ==2){

            self.btnalignment=UIControlContentHorizontalAlignmentRight;

        }else if([dict[@"btnaligmentmark"]integerValue] ==3){

            self.btnalignment=UIControlContentHorizontalAlignmentFill;

        } else{

            self.btnalignment=UIControlContentHorizontalAlignmentCenter;

        }

    }else {

        self.btnalignment=UIControlContentHorizontalAlignmentCenter;

    }

    

//按钮是否选中

    if([[dictallKeys]containsObject:@"isSelectedBtn"] && [dict[@"isSelectedBtn"]boolValue]!=0){

        self.isSelectedBtn=[dict[@"isSelectedBtn"]boolValue];

    }else{

        self.isSelectedBtn=NO;

    }

    

}

@end

 

------------UIButton的setBacgrounImage和setImage的使用区别:-----------

在将 UIButton 当做图标按钮使用时,可以有两种方式给它设置一张图片:setBackgroundImage:forState: 和 setImage:forState:。用这两种方式都可以把 UIButton 作为图片按钮使用,这在图片背景的比例和UIButton 的宽高比例相同时是没什么问题的,图片都不会因为被拉伸或者缩放而出现失真。但是当图片的比例和 Button 的尺寸比例不一样时,这两种方式设置图片的效果就不一样了;

如果不做任何设置,setBancegroundinmge和setImage都会使图片被拉升;

对于setImage:forState:设置的图片可以给 UIButton 的 imageView 设置对应的填充属性来解决缩放问题,注意不是直接设置 UIButton 的 contentModesetImage:forState: 会将 image 设置到 UIButton 中的 ImageView 图层,直接设置 UIButton 的 contentMode 是不起作用的。对于用 setBackgroundImage:forState: 方式设置的图片,无论怎么设置都不会有效果,这种方式会直接将图片拉伸至 Button 的边界,来填充满整个 Button。所以如果 图片和 Button的比例不一致时,只能使用 setImage:forState: 这种方式来保证图片不被压缩。 

但是,当 Button 的大小超过了图片的原始大小,并且比例也不一样时,这时候 Button 四周就可能会出现图片覆盖不上的空白;

设置 button.imageView?.contentMode = .ScaleAspectFill 的确会让图片不再变形,但是也只是按图片的原始尺寸显示了,两边的留白也是很不美观的。当然,这也是有解决办法的,UIControl 里提供了两个属性:contentHorizontalAlignment 和 contentVerticalAlignment 分别用来设置水平和竖直方向上内容的对齐方式,把 button1 的 contentHorizontalAlignment 设置为 Fill 就可以解决上面的问题,如果是竖直方向无法填满的话,设置 contentVerticalAlignment 就行了。

 

btn.imageview.contemmode的填充模式:参考:

 UIViewContentModeScaleAspectFil:将图片等比例拉伸,会填充整个UIImageView,但是会有一部分过大而超出区域

  • ScaleToFill为:将图片按照整个区域进行拉伸(会破坏图片的比例) 
  • UIViewContentModeScaleAspectFit:将图片等比例拉伸,不会填充满整个区域 ,这个图片都会在view里面显示,并且比例不变 这就是说 如果图片和view的比例不一样 就会有留白
  • UIViewContentModeScaleAspectFill:将图片等比例拉伸,会填充整个区域,但是会有一部分过大而超出整个区域。个view会被图片填满,图片比例不变,如果超出位置的可以截取掉;

    [self.prp_imageViewsetContentMode:UIViewContentModeScaleAspectFill];

    self.prp_imageView.clipsToBounds = YES;

    至于Top,Left,Right等等就是将图片在view中的位置进行调整。

其其他模式:

/    UIViewContentModeRedraw,

//    UIViewContentModeCenter,           

//    UIViewContentModeTop,

//    UIViewContentModeBottom,

//    UIViewContentModeLeft,

//    UIViewContentModeRight,

//    UIViewContentModeTopLeft,

//    UIViewContentModeTopRight,

//    UIViewContentModeBottomLeft,

//    UIViewContentModeBottomRight,

 

 

----------按钮中内容的对其方式-------

 

btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;

 

 UIControlContentHorizontalAlignmentCenter = 0,

    UIControlContentHorizontalAlignmentLeft   = 1,

    UIControlContentHorizontalAlignmentRight  = 2,

    UIControlContentHorizontalAlignmentFill   = 3,

    UIControlContentHorizontalAlignmentLeading  = 4,

    UIControlContentHorizontalAlignmentTrailing

 

 

 

 

btn.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

 

UIControlContentVerticalAlignmentCenter  = 0,

 

    UIControlContentVerticalAlignmentTop     = 1,

    UIControlContentVerticalAlignmentBottom  = 2,

    UIControlContentVerticalAlignmentFill    = 3,

 

--------titleEdge和imageEdge-------

 

 

----------多按钮排列

@interface LYHomeTabHeaderview()@property(nonatomic,strong)NSArray *imageArr;@property(nonatomic,strong)NSArray *titleArr;@end@implementation LYHomeTabHeaderview-(NSArray *)titleArr{    if(nil==_titleArr){          _titleArr=@[@"安心门店",@"每日签到",@"店面体验",@"拍卖",@"论坛",@"会员卡充值",@"教育",@"介绍"];    }    return _titleArr;}-(NSArray *)imageArr{    if(nil==_imageArr){        _imageArr=@[@"anxinmendian",@"meiriqiandao",@"dianmiantiyan",@"anxinpaimai",@"anxinluntan",@"huiyuankachongzhi",@"anxinjiaoyu",@"qiyejieshao"];    }    return _imageArr;}-(instancetype)initWithFrame:(CGRect)frame{    if(self==[super initWithFrame:frame]){        [self initviews];    }    return self;}-(void)initviews{         [self fourbtnView];//四个按钮    }-(void)fourbtnView{    UIView *fourbtnView=[[UIView alloc]initWithFrame:CGRectMake(0, 183, WIDTH, 99+79)];    fourbtnView.backgroundColor=[UIColor whiteColor];    UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 1)];    line.backgroundColor=[UIColor colorWithHexString:@"#f6f6f6" alpha:1];    [fourbtnView addSubview:line];    [self addSubview:fourbtnView];        CGFloat w=44;//图片宽度和高度    CGFloat margin=25;//水平间隔    CGFloat midsep=(WIDTH-(44+20)*4-margin*2)/3;    CGFloat h=66;//竖向跨度    CGFloat y=15;//距顶部的距离      NSInteger count=4;//一排4个         for (int i=0; i<8; i++) {        UIView *bv=[[UIView alloc]initWithFrame:CGRectMake(margin+i%count*(w+20+midsep),i/count*(y+h), w+20,y+h)];         [fourbtnView addSubview:bv];        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10,y, w, w)];        btn.tag=9999+i;        [btn setImage:[UIImage imageNamed:self.imageArr[i]] forState:UIControlStateNormal];        [btn addTarget:self action:@selector(fourbtnViewclick:) forControlEvents:UIControlEventTouchUpInside];        [bv addSubview:btn];                UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0,y+w+12, w+20, 12)];        lbl.tag=9999+i;        lbl.text=self.titleArr[i];        lbl.textAlignment=NSTextAlignmentCenter;        lbl.textColor=[UIColor colorWithHexString:@"#121212" alpha:1];        lbl.font=[UIFont systemFontOfSize:12];        [bv addSubview:lbl];    }}-(void)fourbtnViewclick:(UIButton *)btn{//    btn.enabled=NO;//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{//        btn.enabled=YES;//    });//    NSLog(@"五个按钮");        NSInteger index=btn.tag-9999;            NSString *titlestr=@"";        if(index==0){//门店            titlestr=@"门店";        }else if(index==1){//每日签到            titlestr=@"每日签到";        }else if(index==2){//店面体验            titlestr=@"店面体验";        }else if(index==3){//拍卖            titlestr=@"拍卖";        }else if(index==4){//论坛            titlestr=@"论坛";        }else if(index==5){//会员卡充值            titlestr=@"会员卡充值";        }else if(index==6){//教育            titlestr=@"教育";        }else if(index==7){//介绍            titlestr=@"介绍";        }       }

*********cell上多个图片布局

//设置cell上的内容哦-(CGFloat)setcellWithDict:(NSDictionary *)dict{    NSString *nickname=dict[@"nickname"];//昵称    [self.nickBtn setTitle:nickname forState:UIControlStateNormal];    self.imagV.image=[UIImage imageNamed:dict[@"img"]];//头像    self.contetnlbl.text=dict[@"content"];//文本内容    NSArray *imgArr=dict[@"imgcontent"];//图片名数组            //*****计算文本的高度 *******给显示的文本一个区域*****        CGSize contentMaxSizes = CGSizeMake(WIDTH-40, MAXFLOAT);        // NSFontAttributeName 字体的大小        NSDictionary *attributesDicts = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};    //计算文本实际宽高的时候, 计算的字体大小要和label中设置的字体大小保持一致        // 根据限定的条件, 来计算text 真实的宽高        CGSize contentRealSizes =  [self.contetnlbl.text boundingRectWithSize:contentMaxSizes options:NSStringDrawingUsesLineFragmentOrigin attributes:attributesDicts context:nil].size;        self.contetnlbl.height=contentRealSizes.height;// 重新设置frame        /*          单图会按照图片等比例显示          多图的图片大小固定          多图如果是4张,会按照 2 * 2 显示          多图其他数量,按照 3 * 3 九宫格显示          */    CGFloat imgcontentviewheight=0;    NSInteger w=(WIDTH-40)/3;    NSInteger count=imgArr.count;    NSInteger row=(count-1)/3+1;//确定行数    CGFloat h=0;//cell 的高度     self.imgContentView.y=CGRectGetMaxY(self.contetnlbl.frame);    if(imgArr.count==0){        self.imgContentView.height=imgcontentviewheight;    }else {        self.imgContentView.height=row*w;    }    //******清空imgContentView上的内容*******    if(self.imgContentView){        for (UIView *v in self.imgContentView.subviews) {            [v removeFromSuperview];        }    }    //***********创建图片    for(int i=0;i

 

转载地址:http://tjmgi.baihongyu.com/

你可能感兴趣的文章
《搜索和推荐中的深度匹配》——2.5 延伸阅读
查看>>
解读:阿里文娱搜索算法实践与思考
查看>>
基于位置的点击模型
查看>>
链表操作算法题合集
查看>>
Crackme3 破解教程
查看>>
奖学金评比系统(数据库系统设计版)
查看>>
HTTP Live Streaming直播
查看>>
rtmp+fms rtmp 视频发布环境
查看>>
最简单的基于librtmp的示例:发布(FLV通过RTMP发布)
查看>>
Windows/Linux下引用jar包,并用javac/java编译运行
查看>>
HttpClient使用详解
查看>>
HttpClient详解(一)
查看>>
httpclient 请求http数据,json转map
查看>>
git 常用命令
查看>>
用递归方法建立二叉树
查看>>
用递归方法对二叉树进行先序、中序和后序遍历
查看>>
翻转二叉树
查看>>
逆序链表
查看>>
epoll 使用详解
查看>>
stl 中 set容器用法
查看>>