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];
  • 相关阅读:
    4.内核编译和裁剪
    2.Linux技能要求
    3.字符驱动框架
    1.Linux命令
    4.类和抽象
    3.指针
    2.C++语言特性
    1.编译器
    计数排序——Counting Sort
    网关、网桥、路由器、集线器
  • 原文地址:https://www.cnblogs.com/marshall-yin/p/4752290.html
Copyright © 2011-2022 走看看