如何检查组件是否为UIView或UIImageView [英] How to check wether the component is UIView or UIImageView

查看:39
本文介绍了如何检查组件是否为UIView或UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个数组.因为我有许多UIView和UIImageView组件,并且我想从该数组中获取每个组件,并且必须知道是imageview还是view,如果是imageview,则必须更改该imageview的图像.但是我没有任何知道如何知道该组件是imageview还是view的想法.如果有人知道,请告诉我识别组件类型的方法.请帮助我解决这个问题.

Hi in my application i have an array. In that i have number of UIView and UIImageView Components, and i want to fetch each component from that array and have to know wether that is imageview or view, if that is imageview i have to change the image for that imageview.But i dont have any idea how to know wether the component is imageview or view. If any one know please let me know the way to recognize the component type. Please help me in this issue.

for (int i=0; i<[array count]; i++){
   // here i have to know wether the component is imageview or view and based on that i have to do below operations 
   UIView *view1=[array objectAtIndex:i];
   NSLog(@"%@",[array objectAtIndex:i]);
   if (130==view1.tag){
       view1.backgroundColor=[UIColor redColor];
    }
    UIImageView *image1=[array objectAtIndex:i];
    if (132==image1.tag){
       image1.image=[UIImage imageNamed:@"Approve2.png"];
    }
}

推荐答案

使用 isKindOfClass

示例:

if ( [originalValue isKindOfClass:[UIImageView class]] ){

   UIImageView *myImageView = (UIImageView *)originalValue;

}

这篇关于如何检查组件是否为UIView或UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆