zoukankan      html  css  js  c++  java
  • 圆形头像图标设计

    #import "MainViewController.h"

     @interface MainViewController ()

     @end

     @implementation MainViewController

     - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

    //    创建圆形头像图标

        UIImageView *avatar=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]autorelease];

    //    指定头像。imageNamed:默认图片格式png,其他图片需加后缀(如.jpg),否则检索不到

        avatar.center=self.view.center;

        avatar.image=[UIImage imageNamed:@"imge2.jpg"];

        avatar.backgroundColor=[UIColor blackColor];

    //    使用CAShapeLayer将视图改为圆形

        CAShapeLayer *shapeLayer=[CAShapeLayer layer];

    //    设置形状路径(使用贝塞尔曲线)

        UIBezierPath *circlePath=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:120 startAngle:0 endAngle:M_PI*2 clockwise:YES];

    //    为形状图层指定路径

        shapeLayer.path=circlePath.CGPath;

    //    为当前视图的图层添加圆形遮罩图层

        avatar.layer.mask=shapeLayer;

        [self.view addSubview:avatar];//avatar:用户头像

     }

  • 相关阅读:
    靶机练习
    靶机练习
    靶机练习
    CTF-攻防世界-Web_php_unserialize(PHP反序列化)
    漏洞复现
    靶机练习
    靶机练习
    靶机练习
    糗事集合
    慕课前端入门-JS事件
  • 原文地址:https://www.cnblogs.com/sxsy-2015/p/4901063.html
Copyright © 2011-2022 走看看