当前位置:网站首页>设置视图动态图片
设置视图动态图片
2022-07-26 09:22:00 【~轻舟~】
设置视图动态图片
本文只是实现一个简单的功能,根据YYKit实现。
首先新建一个项目,用终端打开输入vim Podfile(前提是你的电脑已经能使用pod管理第三方了) 将YYkit用cocopod集成,好了,前期准备工作已经完成,接下来开始写。
新建一个类MineHeaderView,在.h中引入 #import
@property (nonatomic, strong) YYAnimatedImageView *headerImgView;//头像
.m文件中:
当不使用xib时系统自动走这个方法:
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.headerImgView setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503377311744&di=a784e64d1cce362c663f3480b8465961&imgtype=0&src=http%3A%2F%2Fww2.sinaimg.cn%2Flarge%2F85cccab3gw1etdit7s3nzg2074074twy.jpg"] placeholder:[UIImage imageWithColor:[UIColor grayColor]]];
}
return self;
}
再写headerImgView的懒加载
- (YYAnimatedImageView *)headerImgView
{
if (!_headerImgView) {
_headerImgView = [YYAnimatedImageView new];
_headerImgView.contentMode = UIViewContentModeScaleToFill;
_headerImgView.userInteractionEnabled = YES;
_headerImgView.layer.cornerRadius = 90/2;
_headerImgView.layer.masksToBounds = YES;
[self addSubview:_headerImgView];
[_headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(90);
make.centerX.centerY.mas_equalTo(self);
}];
}
return _headerImgView;
}
这里面用的了masonry所以在倒入YYKit时,将Masonry一起导入,这样的话MineHeaderView这个类完成,接下来就是使用。
在ViewController中引入#import “MineHeaderView.h”
给headerView一个声明
@property (nonatomic, strong) MineHeaderView *headerView;//头部视图
创建UI
- (void)createUI
{
self.headerView = [[MineHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 260)];
self.headerView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.headerView];
}
调用这个方法即可实现。
边栏推荐
- QT | about how to use EventFilter
- Canal 的学习笔记
- The problem of the sum of leetcode three numbers
- 【ARKit、RealityKit】把图片转为3D模型
- Qtcreator reports an error: you need to set an executable in the custom run configuration
- The essence of attack and defense strategy behind the noun of network security
- What is asynchronous operation
- Redis principle and use - Basic Features
- NTT (fast number theory transformation) polynomial inverse 1500 word analysis
- [use of final keyword]
猜你喜欢
【线上死锁分析】由index_merge引发的死锁事件
Under a directory of ext3 file system, subfolders cannot be created, but files can be created
分布式跟踪系统选型与实践
Bloom filter
arc-gis基础操作3
Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
【Flutter -- 布局】Align、Center、Padding 使用详解
【Mysql】一条SQL语句是怎么执行的(二)
volatile 靠的是MESI协议解决可见性问题?(下)
redis原理和使用-安装和分布式配置
随机推荐
Simple message mechanism of unity
布隆过滤器
MySQL transaction
ZXing简化版,转载
(2006, MySQL server has gone away) problem handling
756. Serpentine matrix
2B and 2C
Nuxt - Project packaging deployment and online to server process (SSR server rendering)
Ext4 file system opens dir_ After nlink feature, link_ Use link after count exceeds 65000_ Count=1 means the quantity is unknown
Sending and receiving of C serialport
JS - DataTables 关于每页显示数的控制
Object 的Wait Notify NotifyAll 源码解析
Cat安装和使用
Polynomial open root
redis原理和使用-安装和分布式配置
OnTap 9 file system limitations
jvm命令归纳
Study notes of dataX
Two tips for pycharm to open multiple projects
I'm faded