Image的AccessibilityIdentifier属性使用
来源:互联网 发布:战争框架淘宝mod 编辑:程序博客网 时间:2024/05/22 16:56
有时候我们使用ImageView的时候想要知道现在的显示的图片是placeHolder的图片还是加载完成或挑选好的图片,但是tag属性只能拿到却不能判断,当然,加几个bool属性也可以完成,但是会有些复杂,如果可以在给imageview赋图片的时候给图片加个标记,那么下次判断一下标记是不是placeHolder就可以了,很简单。
代码:
// swift
let picView = UIImageView(frame:CGRectMake(10,90,50,50))
picView.layer.cornerRadius =3
picView.userInteractionEnabled =true
picView.layer.masksToBounds =true
picView.image =UIImage(named:"add_pic.png")
picView.image?.accessibilityIdentifier ="add"
这个图片 “add_pic.png”的标记就是 “add”,当你更换picview的image时,如果不给AccessibilityIdentifier属性重新赋值的话,这个属性的值就会变成null,每个图片都会对应一个专属的AccessibilityIdentifier;方便我们识别图片。
// 判断
if picView.image?.accessibilityIdentifier =="add" {
//是默认图、替换图片
self.chooseImaeFromAblum({ (image) -> (Void)in
picView.image = image
picView.accessibilityIdentifier ="new"
})
}else{
//(ImageView中不是默认图)查看大图或进行其他操作
}
// oc
UIImageView * picView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 90, 50, 50)];
picView.layer.cornerRadius = 3;
picView.userInteractionEnabled = YES;
picView.layer.masksToBounds = YES;
picView.image = [UIImageimageNamed:@"add_pic.png"];
[picView.imagesetAccessibilityIdentifier:@"add”];
if ([picView.image.accessibilityIdentifierisEqualToString:@"add"]) {
[self chooseImageFromAblum:^(UIImage*image) {
picView.image = image;
// 给新图片的AccessibilityIdentifier赋新值
[picView.imagesetAccessibilityIdentifier:@"new"];
}];
}else{
[self blowUpImageWithPic:picView.image];
}
这样会方便很多,减少bool变量过多带来的问题。
- Image的AccessibilityIdentifier属性使用
- UIImage 的 AccessibilityIdentifier 属性的使用
- AccessibilityIdentifier属性使用
- UIImageView 属性 accessibilityIdentifier
- AccessibilityIdentifier
- image的srcset属性
- image的srcset属性
- WCF Image控件的Source属性的使用
- UGUI的image的属性
- 重写UIImageView的image属性
- grub-image的使用
- Image Switcher的使用
- border-image的使用
- new Image()的使用
- 组件Image的使用
- Image-Loader的使用
- WinCE如何使用PictureBox的Image属性通过图片路径显示图片
- Flex中Application的Image属性
- 按首字符的大小,进行字符串排序
- poj1321 深搜。。呵呵
- 炫酷的circleprogress
- MINUS,INTERSECT和UNION ALL比较
- Mapnik概述
- Image的AccessibilityIdentifier属性使用
- C# 实现打开和关闭可执行文件
- hdu 2853
- C#常用的命名规则汇总
- Oracle 数据库导入导出 dmp文件
- 前段开发高段课程
- 在函数中以数组作为形参的方法
- thinkpad L440关闭触摸屏
- HDU3400(三分)