UI图像视图问题

发布于 2024-08-10 03:06:05 字数 1250 浏览 5 评论 0原文

我的应用程序中有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

物价感观 2024-08-17 03:06:05

要更改图像本身,您可以编写:

UIImage* myNewImage = ...;
myImageView.image = myNewImage;

要更改 UIImageView 的背景,您可以编写:

myImageView.backgroundColor = [UIColor redColor];

... 或您想要的任何其他 UIColor ,包括用作图案的另一图像。

To change the image itself, you can write:

UIImage* myNewImage = ...;
myImageView.image = myNewImage;

To change the background of your UIImageView, you can write:

myImageView.backgroundColor = [UIColor redColor];

... or whatever other UIColor you would like, including another image used as a pattern.

一个人练习一个人 2024-08-17 03:06:05

如果您在视图控制器类中实现 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文