ios TableView设置背景图片

我也真是服了,就这个小东西,说了大家可能不信,我做了一天,终于弄出来了,现在看看,真是自己太弱智了,受不了自己这么低效,写这篇博客纪念一下:

!!!!!!!!!!!!!!!!!!!!!!!

核心代码:

if (!mBackgroundView) {
                mBackgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, WIDTH_SCREEN, HEIGHT_SCREEN-64)];
                [self addSubview:mBackgroundView];
            }
            if (!mPriceTableView) {
                mPriceTableView = [[UITableView alloc]initWithFrame:CGRectMake(WIDTH_SCREEN/3*2-16, 190, WIDTH_SCREEN/3,125) style:UITableViewStylePlain];
                UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"settingPrice"]];
                imageView.frame =self.bounds;
              //  imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                mPriceTableView.backgroundColor = [UIColor clearColor];
                [mPriceTableView setBackgroundView:imageView];
                mPriceTableView.delegate = self;
                mPriceTableView.dataSource = self;
                mPriceTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
                mPriceTableView.rowHeight = 125/4;
                mPriceTableView.showsVerticalScrollIndicator = NO;
                mPriceTableView.scrollEnabled = NO;
                if ([mPriceTableView respondsToSelector:@selector(setLayoutMargins:)]) {
                    [mPriceTableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
                }
            }
            if (![mPriceTableView superview]) {
                [mBackgroundView addSubview:mPriceTableView];
            }
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeClick:)];
            tap.delegate = self;
            [mBackgroundView addGestureRecognizer:tap];

创建一个imageView,设置它的图片为某一张图片,然后就是调用tableView的setBackgroundView,即可。。。对了,还得设置cell的背景色为透明,不是cell.contentView

今天还学到了一点,比如说设置view的背景图片 

UIView *view = [[UIView alloc]init];
[view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@""]]];

分享一下至此。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值