zoukankan      html  css  js  c++  java
  • 在UIView中加入应用下载信息模块

    -(void)willMoveToSuperview:(UIView *)newSuperview
    {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"books.plist" ofType:nil];
        _books = [NSArray arrayWithContentsOfFile:path];
        
        NSLog(@"%@",_books);
        
        self.frame = newSuperview.bounds;
        self.backgroundColor = [UIColor redColor];
        int totalColumns = 3;
        
        // 应用的尺寸
        CGFloat bookW = 90;
        CGFloat bookH = 125;
        
        // 间隙 = (view的宽度 - 3 * 应用宽度) / 4
        CGFloat marginX = (self.frame.size.width - totalColumns * bookW) / (totalColumns + 1);
        CGFloat marginY = 15;
        
        // 依据应用个数创建相应的框(index)
        for (int index = 0; index<self.books.count; index++) {
            // 创建
            UIView *bookView = [[UIView alloc] init];
            // 设置背景色
            bookView.backgroundColor = [UIColor cyanColor];
            
            // 计算框的位置
            // 计算行号和列号
            int row = index / totalColumns;
            int col = index % totalColumns;
            // 计算x和y
            CGFloat bookX = marginX + col * (bookW + marginX);
            CGFloat bookY = 20 + row * (bookH + marginY);
            // 设置frame
            bookView.frame = CGRectMake(bookX, bookY, bookW, bookH);
            
            //加入框到控制器的view
            [self addSubview:bookView];
            
            // 加入控件
            // index位置相应的应用信息
            NSDictionary *bookInfo = self.books[index];
            
            // 加入图片
            //UIImageView *iconView = [[UIImageView alloc] init];
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setBackgroundImage:[UIImage imageNamed:bookInfo[@"icon"]] forState:UIControlStateNormal];
            // 设置位置
            CGFloat iconW = 60;
            CGFloat iconH = 80;
            CGFloat iconX = (bookW - iconW) * 0.5;
            CGFloat iconY = 0;
            btn.frame = CGRectMake(iconX, iconY, iconW, iconH);
            [bookView addSubview:btn];
            
            // 加入名字
            UILabel *nameLabel = [[UILabel alloc] init];
            // 设置位置
            CGFloat nameW = bookW;
            CGFloat nameH = 20;
            CGFloat nameX = 0;
            CGFloat nameY = iconY + iconH;
            nameLabel.frame = CGRectMake(nameX, nameY, nameW, nameH);
            // 设置文字
            nameLabel.text = bookInfo[@"name"];
            // 设置字体
            nameLabel.font = [UIFont systemFontOfSize:13];
        
            // 设置文字居中对齐
            nameLabel.textAlignment = NSTextAlignmentCenter;
            [bookView addSubview:nameLabel];
            
            // 加入下载按钮
            UIButton *downloadBtn = [[UIButton alloc] init];
            // 设置位置
            CGFloat downloadX = 12;
            CGFloat downloadY = nameY + nameH;
            CGFloat downloadW = bookW - 2 * downloadX;
            CGFloat downloadH = 20;
            downloadBtn.frame = CGRectMake(downloadX, downloadY, downloadW, downloadH);
            // 设置默认的背景
            
            UIImage *normalImage = [UIImage imageNamed:@"upomp_button_keyboard3"];
            [downloadBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
            // 设置高亮的背景
            UIImage *highImage = [UIImage imageNamed:@"upomp_button_keyboard3_highlighted"];
            [downloadBtn setBackgroundImage:highImage forState:UIControlStateHighlighted];
            // 设置按钮的文字
            [downloadBtn setTitle:@"download" forState:UIControlStateNormal];
           
            // 设置按钮文字的字体
            
            downloadBtn.titleLabel.font = [UIFont systemFontOfSize:13];
            [bookView addSubview:downloadBtn];
        }
        
        
    
    }
    

  • 相关阅读:
    嵌入级联分类器
    AdaBoost 和 Real Adaboost 总结
    二分图匹配--匈牙利算法
    更新说明
    使用Visual Studio 2015 Community 开发windows服务
    C#字符串的不变性
    Windows 7 IIS HTTP 错误 500.21 – Internal Server Error 解决方法
    asp.net的请求管道事件
    Http请求过程
    css简单学习属性2---背景图片
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7065666.html
Copyright © 2011-2022 走看看