使用UIScrollView实现带title的九宫格

 NSArray *array3 =[responseObject objectForKey:@"recommends"];
         NSMutableArray *a = [[NSMutableArray alloc]init];
        for(int k =0;k<[array3 count];k++){
              SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithTitle:@"" imageUrl:@"http://pic28.nipic.com/20130401/10680939_140035693107_2.jpg" placeholderImage:[UIImage imageNamed:@"ad.png"] tag:k];
             [a addObject:item];
        }

        SGFocusImageFrame *imageFrame = [[SGFocusImageFrame alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 180.0) delegate:self items:a];

        
        
        [self.scrollView addSubview:imageFrame];
        
        
        
        
        
        
        
       NSArray *array =[responseObject objectForKey:@"list"];
        for(int i=0;i<[array count];i++){
            //设置标题
            
            
            
            
            //标题
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(5,230*i+(i*30)+15+180, 3,15)];
            [view setBackgroundColor:RGB(28.0, 191.0, 98.0)];
            [self.scrollView addSubview:view];
            UILabel *btn = [[UILabel alloc] initWithFrame:CGRectMake(0,230*i+(i*30)+8+180, 320, 30)];
            [btn setText:[NSString stringWithFormat:@"   %@",[array[i] objectForKey:@"name"]]];
            [btn setTextColor:[UIColor blackColor]];
            [self.scrollView addSubview:btn];
            
            
             NSArray *array2 =[array[i] objectForKey:@"content"];
            
            
            for(int j=0;j<[array2 count];j++){
              
                NSLog(@"-----===-->%@",array2[j]);
                //一个Item    (view.frame.origin.y+40)*j
                MyButton *button = [[MyButton alloc]initWithFrame:CGRectMake(j%2==0?162:6, view.frame.origin.y+((ceil( j / 2)) * 115)+30, 150, 105)];
//                [button setBackgroundColor:[UIColor redColor]];
                button.titleLabel.textColor=[UIColor clearColor];
                [button addTarget:self action:@selector(itemOnClick:) forControlEvents:UIControlEventTouchUpInside];
                [button setObject:array2[j]];
//
                UIImageView *imgBgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 150, 80)];
                
//                imgBgView.image = [UIImage imageNamed:@"video-pic2.png"];
                [imgBgView setImageWithURL:[NSURL URLWithString:[array2[j] objectForKey:@"videoImage"]] placeholderImage:[UIImage imageNamed:@"video-pic2.png"]];
                [button addSubview:imgBgView];
                
//                
                UILabel *headLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, 150, 20)];
                [headLabel setBackgroundColor:[UIColor clearColor]];
                [headLabel setBackgroundColor:RGBA(0.0, 0.0, 0.0,0.5f)];
                [headLabel setText:[NSString stringWithFormat:@" %@",[array2[j] objectForKey:@"videoName"]]];
                [headLabel setFont:[UIFont systemFontOfSize:14.0f]];
                [headLabel setTextColor:[UIColor whiteColor]];
                [button addSubview:headLabel];
//
//                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 83, 150, 20)];
                label.text = [NSString stringWithFormat:@"%@",[array2[j] objectForKey:@"videoIntroduction"]];
                label.backgroundColor = [UIColor clearColor];
                label.textAlignment = UITextAlignmentLeft;
                label.font = [UIFont systemFontOfSize:14];
                [button addSubview:label];
                
                [_scrollView addSubview:button];
            
            }
            
            
            
            
            
            [self.scrollView setContentSize:CGSizeMake(320, (266.7*[array count])+180)];
            
            
            
        }




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值