NavigationItem.titleView添加视图(切割圆角图)

#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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容