[iOS imageView]headImage 异形图片的画法(小技巧记录)

news/2024/7/20 22:38:36 标签: ios, imageview, 图片, 控件, 异形

先看成品

这里写<a class=图片描述" title="" />
头像上既不是圆形,也不是方形,好像iOS的控件里也没有这样的异形控件

这样的效果其实是这样做的,
首先
问设计要这样两张图
图一
这里写<a class=图片描述" title="" />

图二
这里写<a class=图片描述" title="" />

关键步骤一
将图二添加到图一中 (小图上添加了一个大图)


    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebar_icon_tx_kb"]];
    UIImageView *imageMaskV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebar_icon_txwk1"]];

为了看的更清楚明白,我self.view的背景色调整一下
于是 会有这种效果
这里写<a class=图片描述" title="" />
继续调整
把图二的center配置到图一的center

 [imageMaskV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(imageV);
    }];

于是
这里写<a class=图片描述" title="" />
填上图片看看效果
这里写<a class=图片描述" title="" />
继续调整
把图一的内边距和图二对齐

[imageMaskV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(imageV).insets(UIEdgeInsetsZero);
    }];

这里写<a class=图片描述" title="" />
然后去掉背景色 添加上我们的图 看看效果

这里写<a class=图片描述" title="" />

完整代码


#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
{

}
@property (nonatomic,strong)UIImageView *imageHeadView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    self.view.backgroundColor = [UIColor orangeColor];

    self.imageHeadView.frame = CGRectMake(30, 30, 60, 60);

    self.imageHeadView.image  = [UIImage imageNamed:@"22"];
    [self.view addSubview:self.imageHeadView];


}


-(UIImageView*)imageHeadView{

    if (!_imageHeadView) {
        _imageHeadView = [self headImage];
    }
    return _imageHeadView;
}


-(UIImageView*)headImage{

    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebar_icon_tx_kb"]];
    UIImageView *imageMaskV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebar_icon_txwk1"]];
       [imageV addSubview:imageMaskV];
    [imageMaskV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(imageV);
    }];



    [imageMaskV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(imageV).insets(UIEdgeInsetsZero);
    }];

    return imageV;

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

http://www.niftyadmin.cn/n/1557663.html

相关文章

前端资源记录

本文章记录我觉得有用的资源 1.Vue源码解析&#xff1a;源码解析地址 描述&#xff1a;vue源码的解析 2.VuePress一个写技术文档的优秀框架:VuePress官方文档 描述&#xff1a;极简静态网站生成器&#xff0c;它包含由 Vue 驱动的主题系统和插件 API&#xff0c;另一个部分是…

小程序转发功能

onShareAppMessage: function () { //添加这个函数事件以后就可以实现点击右上角转发的功能&#xff08;非常牛逼重要&#xff09;return {title: "后门咨询", //转发的标题path: "/pages/search/search" //要转发的页面路径以及参数}}转载于:https://www.…

[iOS 扩展转] iOS扩展开发-Today扩展share扩展

http://blog.csdn.net/jianxin160/article/details/51834075 最新的iOS 9 新增的extension 扩展的知识点 包括了 键盘/today/share/等等的扩展应用 这里转载一下,收藏起来!!! 概述 从iOS 8 开始Apple引入了扩展&#xff08;Extension&#xff09;用于增强系统应用服务和应…

Cesium对entity的操作以及资源记录(增删改查)

首先这个不是我写的&#xff0c;我看到了感觉还不错记录一下&#xff0c;分享给大家。 cesium Entity实体操作 再给大家分享一个cesium的中文api网址以及一些教程网址 cesium中文网 cesium官方示例&#xff08;有时会很卡&#xff09; cesium社区 cesium官方 ce…

[iOS 自动打包上传并自动上传蒲公英]

关于自动打包的文章 可以参考这个 [iOS 自动打包]shell脚本使用-ipa_build 脚本使用 这一次,我是把 自动上传蒲公英 的代码 结合到 ipa-build 这个shell脚本中去, 这样 我们就可以用一个脚本去实现 自动打包并上传到蒲公英 # 发布到蒲公英 #xcrun打包 xcrun -sdk iphoneos P…

react16.13新特性

最近做一个项目用到了react16&#xff0c;目录和之前完全不一样&#xff0c;配置路由&#xff0c;代理&#xff0c;antd按需加载之类的费了很长时间&#xff08;尤其暴露webpack配置&#xff09;。而且react16新增了很多特性和功能。 一、新特性 1.这是我觉得还不错的博客&am…

很实用的进度条插件ProgressBar.js ProgressBar.js配置参数详解

1&#xff0c;介绍 它是响应式的创建SVG元素的一个插件。不要慌&#xff0c;不懂SVG也没有关系&#xff0c;插件的使用&#xff0c;主要是对配置参数的理解。 这是ProgressBar.js的网站&#xff0c;有动效的展示&#xff08;我截的静态的图。。。&#xff09;&#xff0c;在如下…

[iOS NSNotifaction通知多次调用] postNotification多次调用问题

背景情况 * 在A控制器ViewController push 到 B控制器中 * B控制器的 ViewDidLoad 方法中 添加了一个通知 并实现了这个通知的方法 问题出现 在第一进入 B 中, 通知方法 被调用一次 在push返回后, 第二次进入 B 中, 通知方法 被调用二次, 在push返回后, 第三次进入 B 中,…