IOS - 商品视图

商品模块代码: 标题+详情+图片

/** * 商品模块 * * @param titleText 标题 * @param descText 描述 * @param imageUrl 图片链接 * @param pos 位置 * * @return 模块视图 */
- (UIView*) getItemViewWithTitleText:(NSString*)titleText
                            descText:(NSString*)descText
                            imageUrl:(NSString*)imageUrl
                                 pos:(int)pos;
{
    if (titleText == nil) titleText = @"标题";
    if (descText == nil) descText = @"描述";

    UIView *contentView; // 主视图

    // 四个部分
    if (pos == 0) {
        contentView = [UIView viewWithFrame: CGRectMake(0, 0, viewWidth()/2, 97 * kviewRatio)
                                 andBkColor: [UIColor clearColor]];
    } else if (pos == 1) {
        contentView = [UIView viewWithFrame: CGRectMake(viewWidth()/2, 0, viewWidth()/2, 97 * kviewRatio)
                                 andBkColor: [UIColor clearColor]];
    } else if (pos == 2) {
        contentView = [UIView viewWithFrame: CGRectMake(0, 97 * kviewRatio, viewWidth()/2, 97 * kviewRatio)
                                 andBkColor: [UIColor clearColor]];
    } else if (pos == 3) {
        contentView = [UIView viewWithFrame: CGRectMake(viewWidth()/2, 97 * kviewRatio, viewWidth()/2, 97 * kviewRatio)
                                 andBkColor: [UIColor clearColor]];
    }

    // 标题
    UILabel* title = [[UILabel alloc] initWithFrame:
                      CGRectMake(20 * kviewRatio, 20 * kviewRatio, 80 * kviewRatio , 25 * kviewRatio)];
    [title setText:titleText];
    [title setFont:[UIFont fontWithName:@"Arial" size:11.0f]];
    [title setTextColor:[UIColor redColor]];
    [contentView addSubview:title];

    // 描述
    UILabel* desc = [[UILabel alloc] initWithFrame:
                     CGRectMake(20 * kviewRatio, 35 * kviewRatio, 80 * kviewRatio , 35 * kviewRatio)];
    [desc setText:descText];
    [desc setFont:[UIFont fontWithName:@"Arial" size:9.0f]];
    [contentView addSubview:desc];

    // 图片
    NINetworkImageView *image = [[NINetworkImageView alloc] initWithFrame:
                                 CGRectMake(110 * kviewRatio, 20 * kviewRatio, 40 * kviewRatio , 60 * kviewRatio)];
    image.defaultImage = [UIImage imageWithColor:[UIColor blackColor] andSize:CGSizeMake(100, 100)];
    image.contentMode = UIViewContentModeScaleAspectFit;
    [image setPathToNetworkImage: imageUrl];

    [contentView addSubview:image];

    return contentView;
}

使用方式

// 模块1
        UIView* item = [self getItemViewWithTitleText:item1[@"title"] descText:item1[@"abstractInfo"] imageUrl:item1[@"downloadUrl"] pos:0]; 
        [contentView addSubview:item];

IOS - 商品视图_第1张图片

你可能感兴趣的:(ios,Mystra)