IOS:用标签值改变 UIImageView

IOS: change UIImageView with tag value(IOS:用标签值改变 UIImageView)
本文介绍了IOS:用标签值改变 UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 20 个 UIImageView,我想更改它们的图像;但我不想创建 20 个 IBOutlet,我想使用标签值来更改图像;我在界面生成器和之后设置标签值?如果我想在 Imageview 15 号更改图像?我该怎么办?

I have 20 UIImageView and i want change their image; but I don't want to create 20 IBOutlet, and I want to use tag value to change the image; I set the tag value in interface builder and after? If I want to change image at Imageview number 15? How can I do?

推荐答案

如果你使用标签,你可以像这样识别你的标签视图(UIImageView 是 UIView 的子类,具有标签属性):

If you use tags you can identify your tagged view (UIImageView is a subclass of UIView, which has the tag attribute) like this:

- (UIView *)viewWithTag:(NSInteger)tag

因此,如果您在您的超级视图(所有 UIImageView 都驻留在其中)上调用此方法,您应该这样做:

So if you call this method on your superview (which all the UIImageViews reside in), you should do it like this:

UIImageView *myImageView = (UIImageView *)[myAwesomeSuperview viewWithTag:15];

(文档 我使用 Google 找到的).

(Documentation I found using Google).

P.S:如果您认为添加 20 个 IBOutlets 工作量太大,我建议您也以编程方式创建 UIImageViews.这样你就完全不需要 xib 文件了,只需要编写一小段代码,就能事半功倍.

P.S: if you think it is too much work to add 20 IBOutlets, I recommend you create the UIImageViews programmatically as well. This way you will not need a xib file at all, write a small piece of code and have better maintenance with less effort.

这篇关于IOS:用标签值改变 UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)