美文网首页
NavigationItem.titleView添加视图(切割圆

NavigationItem.titleView添加视图(切割圆

作者: DemoFootMan | 来源:发表于2016-05-30 19:37 被阅读0次

    #pragma mark -- 创建主页图像视图

    -(void)createScaleHeadView {

    UIView *topHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,78,44)];

    topHeadView.backgroundColor = [UIColor clearColor];

    _topImageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 78, 78)];

    _topImageView.backgroundColor = [UIColor whiteColor];

    _topImageView.layer.cornerRadius = _topImageView.bounds.size.width /2.;

    _topImageView.layer.anchorPoint = CGPointMake(0.5, 0.5);

    _topImageView.image = [UIImage imageNamed:@"head"];

    //******切割圆形头像*******************

    UIGraphicsBeginImageContext(_topImageView.bounds.size);

    CGRect imageRect =CGRectMake(0, 0, 78, 78);

    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:imageRect];

    [[UIColor redColor] setStroke];

    path.lineWidth =1;

    [path stroke];

    [path addClip];

    UIImage *image =[UIImage imageNamed:@"head"];

    [image drawInRect:imageRect];

    //用画布生成一个image对象

    UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();

    //关闭绘制 的上下文区间

    UIGraphicsEndPDFContext();

    _topImageView.image =newImage;

    //******切割圆形头像***************************************

    [topHeadView addSubview:_topImageView];

    self.navigationItem.titleView = topHeadView;

    }

    相关文章

      网友评论

          本文标题:NavigationItem.titleView添加视图(切割圆

          本文链接:https://www.haomeiwen.com/subject/ltlcdttx.html