• iOS Coding项目片段记录(五)


    1.设置UIButton  UIView 等显示渐变的背景颜色

    - (void)setBackgroundColorWithButton:(UIButton *)button  firstColor:(UIColor *)firstColor lastColor:(UIColor *)lastColor{
    
        CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
        gradientLayer.colors = @[(__bridge id)firstColor.CGColor,(__bridge id)lastColor.CGColor];
    
        gradientLayer.startPoint = CGPointMake(0, 0);
    
        gradientLayer.endPoint = CGPointMake(0, 1);
    
        gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(button.frame), CGRectGetHeight(button.frame));
    
        [button.layer addSublayer:gradientLayer];
    }
    UIColor *firstColor = [UIColor colorWithRed:(128/256.0) green:(215/256.0) blue:(4/256.0) alpha:1];
        UIColor *lastColor = [UIColor colorWithRed:(41/256.0) green:(129/256.0) blue:(1/256.0) alpha:1];
        [self setBackgroundColorWithButton:_myButton1 firstColor:firstColor lastColor:lastColor];

    2.给图片增加一个外围的白色边框

    -(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
        
        //UIGraphicsBeginImageContext(image.size);
        //解决失真 模糊的问题
        UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);
        CGContextRef context =UIGraphicsGetCurrentContext();
        
        //圆的边框宽度为2,颜色为红色
        
        CGContextSetLineWidth(context,2);
        
        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
        
        CGRect rect = CGRectMake(inset, inset, image.size.width - inset *2.0f, image.size.height - inset *2.0f);
        
        CGContextAddEllipseInRect(context, rect);
        
        CGContextClip(context);
        
        //在圆区域内画出image原图
        
        [image drawInRect:rect];
        
        CGContextAddEllipseInRect(context, rect);
        
        CGContextStrokePath(context);
        
        //生成新的image
        
        UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        return newimg;
        
    }
  • 相关阅读:
    微信redirect_uri 回调错误,scope权限错误
    对“空间数据库”的理解
    空间数据库2
    PostgreSQL和MySQL
    shp文件和地理数据库文件的区别
    分布式 空间数据库
    Git使用教程
    栅格投影
    mapnik渲染原理
    高斯消元——浮点数模板
  • 原文地址:https://www.cnblogs.com/741162830qq/p/6030896.html
Copyright © 2020-2023  润新知