• 设置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;
    }

  • 相关阅读:
    Biba模型简介
    Fragment 与 Activity 通信
    小米2S 连接Ubuntu Android Studio
    【转】Android 实现“再按一次退出程序”
    取消 EditText 自动聚焦弹出输入法界面
    为Android Studio 项目手动下载gradle
    【转】Java读取文件方法大全
    sudo: /etc/sudoers 的模式为 0551,应为 0440
    Win7 下硬盘安装Linux Mint 17
    Linux Versus Windows, Ubuntu/Mint V XP/Vista/7
  • 原文地址:https://www.cnblogs.com/GnagWang/p/2189581.html
Copyright © 2020-2023  润新知