UI图像视图问题
我的应用程序中有一个 UIImageview,我想知道如何在其中实用地显示图像并在需要时更改它!我认为我的主要问题就是把它放在哪里!如果你能告诉我什么代码以及在哪里,那将非常有用!谢谢!
编辑:此外,如果您可以实用地将背景更改为图像甚至颜色!谢谢!或者或者都会起作用!
EDIT2:这是我的代码,我不知道把它们放在哪里,因为它们总是给我一个错误!
MainView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface MainView : UIView {
//static int r;
int r;
IBOutlet UIButton *myButton;
IBOutlet UILabel *myTextLabel;
IBOutlet UILabel *myTextLabel2;
IBOutlet UIImageView *myImage;
}
@property (nonatomic, retain) UIButton *myButton;
@property (nonatomic, retain) UILabel *myTextLabel;
@property (nonatomic, retain) UILabel *myTextLabel2;
@property (nonatomic, retain) UIImageView *myImage;
- (IBAction)buttonclick;
//+(void) initialize;
@end
和
MainView.m
#import "MainView.h"
#include <stdlib.h>
#include <libc.h>
@implementation MainView
@synthesize myButton, myTextLabel, myTextLabel2, myImage;
- (IBAction)buttonclick {
r++;
if(r == 1) {
self.myTextLabel.text = @"word";
self.myTextLabel2.text = @"def.";
}else if(r == 2) {
self.myTextLabel.text = @"word2";
self.myTextLabel2.text = @"def2 ";
}
}
@end
I have a UIImageview in my application and I was wondering how I can show an image in it pragmatically and change it whenever I want to! I think my major problem is exactly WHERE to put it! If you could show me what code and where that would be very usefull! thanks!
EDIT: Also if you can pragmatically change the background into an image or even a color! thanks! either or will work!
EDIT2: here is my code, i dont know where to put those because they always give me an error!
MainView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface MainView : UIView {
//static int r;
int r;
IBOutlet UIButton *myButton;
IBOutlet UILabel *myTextLabel;
IBOutlet UILabel *myTextLabel2;
IBOutlet UIImageView *myImage;
}
@property (nonatomic, retain) UIButton *myButton;
@property (nonatomic, retain) UILabel *myTextLabel;
@property (nonatomic, retain) UILabel *myTextLabel2;
@property (nonatomic, retain) UIImageView *myImage;
- (IBAction)buttonclick;
//+(void) initialize;
@end
and the
MainView.m
#import "MainView.h"
#include <stdlib.h>
#include <libc.h>
@implementation MainView
@synthesize myButton, myTextLabel, myTextLabel2, myImage;
- (IBAction)buttonclick {
r++;
if(r == 1) {
self.myTextLabel.text = @"word";
self.myTextLabel2.text = @"def.";
}else if(r == 2) {
self.myTextLabel.text = @"word2";
self.myTextLabel2.text = @"def2 ";
}
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要更改图像本身,您可以编写:
要更改 UIImageView 的背景,您可以编写:
... 或您想要的任何其他
UIColor
,包括用作图案的另一图像。To change the image itself, you can write:
To change the background of your UIImageView, you can write:
... or whatever other
UIColor
you would like, including another image used as a pattern.如果您在视图控制器类中实现 viewDidLoad() 方法,您可以在视图中设置图像。当自动调用此方法时,所有 IBOutlet 将被初始化,并允许您设置 myImageView.image。
请参阅 viewDidLoad
If you implement the viewDidLoad() method in your view controller class you can set the image in the view there. When this method is automatically invoked all of your IBOutlets will be initialized already allowing you to set myImageView.image.
See viewDidLoad