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];
  • 相关阅读:
    MySQL之ORM
    MySQL之索引补充
    MySQL存储过程
    c primer plus 7编程练习
    c语言中统计单词数目程序
    c语言统计输入字符数及行数
    c语言中getchar()、putchar()函数例子
    c primer plus 6编程练习
    c语言 %c 一次输出多个字符 (特殊程序)
    c语言 复合赋值运算符的优先级低于算术运算符
  • 原文地址:https://www.cnblogs.com/marshall-yin/p/4752290.html
Copyright © 2011-2022 走看看