zoukankan      html  css  js  c++  java
  • 设置Table Cell的背景图的类

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>

    @interface UITableViewCell (UITableViewCellExt)

    - (void)setBackgroundImage:(UIImage*)image;
    - (void)setBackgroundImageByName:(NSString*)imageName;

    @end


    #import "UITableViewCellExt.h"


    @implementation UITableViewCell (UITableViewCellExt)

    - (void)setBackgroundImage:(UIImage*)image
    {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.contentMode = UIViewContentModeCenter;
        self.backgroundView = imageView;
        [imageView release];
        
    }

    - (void)setBackgroundImageByName:(NSString*)imageName
    {
        [self setBackgroundImage:[UIImage imageNamed:imageName]];
    }


    @end

    调用示例:

    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            [cell setBackgroundImageByName:@"text-background.png"];
            
            
        }
        
        return cell;
    }

  • 相关阅读:
    职位晋升的潜规则
    mybatis中的多对多的查询
    mybatis的自关联查询
    Git使用步骤
    Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
    Spring中的前置增强和后置增强
    Spring中的异常增强
    mybatis中session.getMapper()方法和resultMap
    mybatis中的多对一的查询
    mybatis中的一对多的查询
  • 原文地址:https://www.cnblogs.com/GnagWang/p/2189581.html
Copyright © 2011-2022 走看看