将 Image 分配给 SubView 中的 UIButton
出色地 !!!!!
我在这里首先解释一下我的应用程序。
我的主视图中有 3 个 UIView,标记为 111,222,333,并且其中有许多按钮。
由于 ViewWithTag 111 有 16 个按钮
由于 ViewWithTag 222 有 20 个按钮
由于 ViewWithTag 333 有 30 个按钮
我隐藏了两个视图,而一次没有一个视图。
现在的问题是,我想在页面加载之前将唯一的图像分配给所有 UI 按钮(在 viewWillAppear 中)。
到目前为止我已经尝试过......
但不起作用......
-(void)setBlankImageToButtons
{
UIImage *btnImage = [UIImage imageNamed:@"blue.jpg"];
for (UIView *subview in [self.view subviews])
{
// Only remove the subviews with tag not equal to 1
if (subview.tag != 0)
{
[self.view bringSubviewToFront:[self.view viewWithTag:111]];
NSLog(@"tag is :%d",subview.tag);
if([subview isKindOfClass:[UIButton class]])
{
[(UIButton *)subview setImage:btnImage forState:UIControlStateNormal];
}
}
}
}
警告:“UIButton”可能不会响应“+Class”
Well !!!!!
I am here explaining about my app first.
I have 3 UIViews in my main View tagged 111,222,333 and having number of buttons in them.
As ViewWithTag 111 have 16 buttons
As ViewWithTag 222 have 20 buttons
As ViewWithTag 333 have 30 buttons
I am hiding the two view while one is not at a time.
Now the problem is, I want to assign the only image to all of my UIbuttons before the page is loaded(In viewWillAppear).
I tried this so far ....
but not working.....
-(void)setBlankImageToButtons
{
UIImage *btnImage = [UIImage imageNamed:@"blue.jpg"];
for (UIView *subview in [self.view subviews])
{
// Only remove the subviews with tag not equal to 1
if (subview.tag != 0)
{
[self.view bringSubviewToFront:[self.view viewWithTag:111]];
NSLog(@"tag is :%d",subview.tag);
if([subview isKindOfClass:[UIButton class]])
{
[(UIButton *)subview setImage:btnImage forState:UIControlStateNormal];
}
}
}
}
warning : 'UIButton' may not respond to '+Class'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它应该是
[UIButton class]
,而不是[UIButton Class]
。It should be
[UIButton class]
and not[UIButton Class]
.类应该是小写:
[UIButton类]
Class should be lower case:
[UIButton class]