Image的AccessibilityIdentifier属性使用
2016-07-28 15:11
295 查看
有时候我们使用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变量过多带来的问题。
代码:
// 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变量过多带来的问题。
相关文章推荐
- Android打造带透明圆弧的ImageView
- Android编程UI设计之GridView和ImageView的用法
- 基于Android实现随手指移动的ImageView
- Android使用ImageView 制作透明圆弧实例代码
- Android中ImageView用法实例分析
- Android使用控件ImageView加载图片的方法
- Android ImageView随手势变化动态缩放图片
- Android程序开发之动态设置ImageView的亮度
- Android实现GridView中ImageView动态变换的方法
- Android控件之ImageView用法实例分析
- 实例解析Android ImageView的scaleType属性
- Android UI之ImageView实现图片旋转和缩放
- Android源码系列之深入理解ImageView的ScaleType属性
- 图文讲解Android的ImageView类中的ScaleType属性设置
- Android手势滑动实现ImageView缩放图片大小
- Android编程实现ImageView图片抛物线动画效果的方法
- Android编程简单实现ImageView点击时背景图修改的方法
- android ImageView 的几点经验总结
- Android控件系列之ImageView使用方法
- Android中通过反射实现圆角ImageView代码实例