zoukankan      html  css  js  c++  java
  • iOS高级-QuartzCore框架-背景平铺

    一、将图片平铺填充整个View

    UIImage *oldImage = [UIImage imageNamed:@"me"];
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size,NO,0.0);
    [oldImage drawInRect:self.view.bounds];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:newImage];

    二、TableView的条纹背景

    //1.创建一行背景图片
    CGFloat rowW = self.view.frame.size.width;
    CGFloat rowH = 40;
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(rowW,rowH), 
    NO,0.0);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //画矩形框
    [[UIColor redColor] set];
    CGContextAddRect(ctx,CGRectMake(0,0,rowW,rowH));
    CGContextFillPath;
    //2.画线
    [[UIColor blackColor] set];
    CGFloat lineWidth =2;
    CGFloat dividerX = 10;
    CGFloat dividerY = rowH - lineWidth;
    CGContextMoveToPoint(ctx,dividerX,dividerY);
    CGContextAddLineToPoint(ctx,rowW - dividerX,dividerY);
    CGContextStrokePath(ctx);
    
    //3.取图
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    //4.结束上下文
    UIGraphicsEndImageContext();
    
    //5.设置为背景色
    self.view.backgroundColor = [UIColor colorWithPatternImage:newImage];
  • 相关阅读:
    springboot运行在eclipse报异常的问题
    Python random模块
    MySQL大小写敏感
    正则表达式详解
    Linux grep命令详解
    Linux printf命令详解
    Linux awk命令详解
    MySQL表介绍
    Linux sed命令详解
    Linux grep命令详解
  • 原文地址:https://www.cnblogs.com/marshall-yin/p/4752290.html
Copyright © 2011-2022 走看看