关闭

uitabview 设置背景

919人阅读 评论(0) 收藏 举报

-(void) changeBaseBackgourndColorWithImageName:(NSString *) imageName

{

#ifdef TARGET_IPAD

    UIImage *image = [UIImage imageNamed:imageName];

    UIImageView *bgImageView = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];

    bgImageView.image = image;

    bgImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    bgImageView.tag = TAGS_CMBT_COLOR_VIEW_BACKGROUNDIMAGEVIEW;

    if ([self.view isKindOfClass:[UITableView class]]) {

        UITableView *tView = (UITableView *)self.view;

        if ([tView respondsToSelector:@selector(setBackgroundView:)]) {

            [tView setBackgroundView:bgImageView];

        }

    }else{

        UIView *bgView = [self.view viewWithTag:TAGS_CMBT_COLOR_VIEW_BACKGROUNDIMAGEVIEW];

        if (bgView) {

            [bgView removeFromSuperview];

        }

        [self.view insertSubview:bgImageView atIndex:0];

    }

#else

    UIColor *bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:imageName]];

    if ([self.view isKindOfClass:[UITableView class]]) {

        UIView *viewi = [[[UIView alloc] initWithFrame:self.view.bounds] autorelease];

        viewi.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        viewi.backgroundColor = bgColor;

        UITableView *tView = (UITableView *)self.view;

        if ([tView respondsToSelector:@selector(setBackgroundView:)]) {

            [tView setBackgroundView:viewi];

        }

    }

    self.view.backgroundColor = bgColor;

#endif

}



 [self changeBaseBackgourndColorWithImageName:@"bg.png"];


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1103792次
    • 积分:15276
    • 等级:
    • 排名:第719名
    • 原创:405篇
    • 转载:193篇
    • 译文:23篇
    • 评论:83条
    博客专栏
    文章分类